You are trying to make an array of arrays, and this is not possible in perl.
When you hear of AoA, it is really an array of array references! So @tlist$tnum is not doing at all what you expected, use strict; use warnings; could have given you some hints about the problem.
I think this is more like what you were trying to achieve (not tested)
foreach $thread (keys %threads) { $tsub[$tnum] = $thread; $tlist[$tnum] = $threads{$thread}; $tsize[$tnum] = @{$tlist[$tnum]}; $tnum++; } print "\n\nThe Thread Arrays\n\n"; for ($i=0;$i<$tnum ;$i++) { print "\n$tsub[$i], size=$tsize[$i], @{$tlist[$i]}"; }
Now @tlist is an array of reference, and it should work.
As a matter of style, I would write it in a slightly different fashion>
# Define the arrays as lexical vars. # So you are sure they are not conflicting with other vars in the prog +ram my @tsub; my @tlist; foreach $thread (keys %threads) { # using push you don't need the counter push(@tsub, $thread); push(@tlist, $threads{$thread}); } print "\n\nThe Thread Arrays\n\n"; for ($i=0;$i<@tsub ;$i++) { # compute tsize only when you need it, another array is useless my $tsize=@{$tlist[$i]}; print "\n$tsub[$i], size=$tsize, @{$tlist[$i]}"; }
Rule One: "Do not act incautiously when confronting a little bald wrinkly smiling man."
In reply to Re: hash of arrays to array of arrays
by psini
in thread hash of arrays to array of arrays
by hsfrey
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |