in reply to Re^5: Problem with traversing a two dimensional array (to create an arrayref use [ ] )
in thread Problem with traversing a two dimensional array
$c's value becomes the last element of the list (90). But if you do this:my $c = qw / 4 6 8 90/;
$c is now 4, the number of elements of the array (I think this would also trigger a warning that @_ may be overwritten). But if you do this:$c = split / /, "the quick brown fox";
now this behaves as an anonymous array et $c is assigned to "brown" (and there no longer any warning, because Perl sort of built an anonymous array). And if you do this:$c = (split / /, "the quick brown fox")[2];
$c's value is now something like "ARRAY(0x80359d10)", i.e. an array reference. and you need something like this:$c = [split / /, "the quick brown fox"];
to print the third element of the array. This is really an array ref, not an array.print $c->[2];
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^7: Problem with traversing a two dimensional array (to create an arrayref use [ ] )
by Anonymous Monk on Jan 16, 2014 at 19:50 UTC | |
by Laurent_R (Canon) on Jan 16, 2014 at 23:19 UTC | |
by no_slogan (Deacon) on Jan 17, 2014 at 00:13 UTC |