Greg_R has asked for the wisdom of the Perl Monks concerning the following question:
The problem is that @AniAry = $AniType{cats} does not result in a copy of the array. I've tried the following as well:%AniType = (cats => ["I", "like", "cats"], dogs => ["I", "like", "dogs"], none => ["I", "like", "neither"], both => ["I", "like", "both"], ); if ($likecats) {@AniAry = $AniType{cats} } elsif ($likedogs) {@AniAry = $AniType{dogs} } elsif ($likeboth) {@AniAry = $AniType{both} } else {@AniAry = $AniType{none} } foreach $line (0..2) { print "$AniAry[$line] MiscArya[$line] MiscAryb[$line] \n"; }
The 2nd option works if I use $AniAry->[0] but that's a reference, not an actual copy like I require. Any help is appreciated, thanks! Greg@AniAry = @{ $AniType{cats} }; $AniAry = $AniType{cats};
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: copying array from a hash reference
by ikegami (Patriarch) on Sep 28, 2011 at 03:13 UTC | |
|
Re: copying array from a hash reference
by davido (Cardinal) on Sep 28, 2011 at 02:37 UTC | |
|
Re: copying array from a hash reference
by AnomalousMonk (Archbishop) on Sep 28, 2011 at 01:19 UTC | |
by Greg_R (Novice) on Sep 28, 2011 at 22:28 UTC | |
|
Re: copying array from a hash reference
by onelesd (Pilgrim) on Sep 28, 2011 at 00:50 UTC |