Johnson, Reginald (GTI) wrote: > I am trying to print the contents of the array from within the hash. I > see that I can do it by > > print "$name: $items[0][0] $items[0][1] $items[0][2] $items[0][3] \n " > > Is there a better way to accomplish this, especially if I don't know the > number of items in the array. > > Here is the code: > while (( my $name, my @items) = each(%all)) {
Hash keys and values are scalars not arrays, although you can store a reference to an array in a scalar: while ( my ( $name, $items ) = each %all ) { > my $len = @items; And then dereference the array: my $len = @$items; > print "this is len=>$len\n"; > # print "$name: $items[0][0] $items[0][1] $items[0][2] > $items[0][3] [EMAIL PROTECTED] \n "; And dereference the elements: # print "$name: $items->[0] $items->[1] $items->[2] $items->[3]\n"; Or use an array slice: # print "$name: @$items[0..3]\n"; > print Dumper(@items); print Dumper $items; > } John -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in short order. -- Larry Wall -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>