chrism01 has asked for the wisdom of the Perl Monks concerning the following question:
and@t_arr2 = ("one", "two", "three"); push(@t_arr, \@t_arr2); @t_arr2 = ("four", "five", "six"); push(@t_arr, \@t_arr2); for $str1 ( @t_arr ) { print "$str1->[0]\n"; print "$str1->[1]\n"; print "$str1->[2]\n"; }
@t_arr2 = ("one", "two", "three"); push(@t_arr, [@t_arr2]); @t_arr2 = ("four", "five", "six"); push(@t_arr, [@t_arr2]); for $str1 ( @t_arr ) { print "$str1->[0]\n"; print "$str1->[1]\n"; print "$str1->[2]\n"; }
The first gives me :
and the 2nd gives mefour five six four five six
The 2nd is the answer I want, but I don't understand the difference between taking an array ref \@arr and taking an array refone two three four five six
plus declarations#!/usr/bin/perl -w use strict;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Array of arrays & references
by xdg (Monsignor) on Mar 15, 2006 at 00:09 UTC | |
|
Re: Array of arrays & references
by rafl (Friar) on Mar 15, 2006 at 00:08 UTC | |
|
Re: Array of arrays & references
by chrism01 (Friar) on Mar 15, 2006 at 00:23 UTC |