in reply to Re^2: Hash of Hash Redux
in thread Hash of Hash Redux
Firstly, you do push(my @chroma, $genea); and push(my @chromb, $geneb); inside the scope of the while ($ranpop) { ... } loop. That means that each time around the loop you create new lexically scoped arrays to push data onto and by the time you get to the return they are out of scope so inaccessible.
Secondly, I'm not sure what you are doing with the
my $center = 1; ... while ($center--) { ... return ... ; }
That loop is meaningless as it stands because it is going to terminate early with the return and would only run the once anyway. If your $center is more than 1 it will still do the same thing as the return will always leave the subroutine. Perhaps the return should me moved to after the loop.
Thirdly, if you want to return more than one array (or hashes for that matter) from a subroutine you must return them by reference because from the caller's point of view, the three arrays you return come back as one big list. Do it something like this.
sub makeArrays { my @arrA = ( 1 .. 6 ); my @arrB = qw{ fred joe bill pete }; my @arrC = ( 1, 3, q{abc}, 8 ); return \@arrA, \@arrB, \@arrC; } my ( $refToArrA, $refToArrB, $refToArrC ) = makeArrays(); my @newArrA = @$refToArrA; my $elemTwoOfArrB = $refToArrB->[2];
I hope this is of use.
Cheers,
JohnGG
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Hash of Hash Redux
by BioNrd (Monk) on Nov 01, 2007 at 00:17 UTC | |
by graff (Chancellor) on Nov 01, 2007 at 05:27 UTC | |
by BioNrd (Monk) on Nov 01, 2007 at 13:23 UTC | |
by graff (Chancellor) on Nov 03, 2007 at 04:10 UTC | |
by BioNrd (Monk) on Nov 05, 2007 at 01:05 UTC |