in reply to Correct syntax to access an array slice within a hash within a hash

Hi! Well, basically you want @{$table{$key}{coords}}[0,3] to get your slice.
you version ($table{$key}{coors}[0,3]) just uses the list 0,3 in a scalar context (i.e. the last element) and so only fetches the value indexed by 3.

a few other points:
  • you use the scalar variable $table in the beginning, later you just use the hash %table.
  • why do you set the value of each hash entry to the same integer as the key? you overwrite that later with a reference to another hash anyway.
  • most important point: use strict; and you would have noticed the other points i've addressed above ;)

    all in all i'd have done something like this:
    #!/usr/bin/perl -w use strict; my %table; for my $i (1..10) { $table{$i} = { shape => $i % 2 ? 'circle' : 'rect', coords => [0,1,2,3,4,5,6,7,8,9] } } foreach my $key (keys %table) { print "Key $key Value $table{$key}\n", "Shape $table{$key}{shape}\n", join(",", @{$table{$key}{coords}}[0,3]), "\n"; }

    snowcrash