in reply to Changling here?

The for loop at the end was a bit of a puzzler because you didn't put your code between <code> </code> tags. See this node.

# original for ($counter = 0; $counter < $array_size; $counter++) { print "\t@$states [ 1 ]->\$counter\\n"; } # did you really mean this? for ($counter = 0; $counter < $array_size; $counter++) { print "\t@$states [ 1 ]->[$counter]\n"; }

If so, once you've got slices and dereferencing under control, this is a clearer and more perlish way to iterate over an array.

for my $city (@{ $states->[1] }) { print "\t$city\n"; } # or for (@{ $states->[1] }) { print "\t$_\n"; }

Replies are listed 'Best First'.
Re^2: Changling here?
by GrandFather (Saint) on May 30, 2008 at 03:41 UTC

    or:

    print "\t$_\n" for @{$states->[1]};

    Perl is environmentally friendly - it saves trees