I'm trying to write various messages across multiple lines based on the current state of my subroutine. These messages need to be placed into an array to be returned to the calling program (it has to be an array due to restrictions of the calling program). I'm using hashes of arrays to define the possible message types and want to copy one of the arrays based on a hash reference into a local array variable. The below code snippet is a generic version of what I'm trying to do:
%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 problem is that @AniAry = $AniType{cats} does not result in a copy of the array. I've tried the following as well:
@AniAry = @{ $AniType{cats} };
$AniAry = $AniType{cats};
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