What do you mean with "convert", do you need a copy of the subarrays or just themself.
use Data::Dumper;
$copy=1; #what you want?
%threads=(
keyA => [ 2, 6, 8 ],
keyB => [ 3, 5, 10, 14, 18 ],
);
$tnum=0;
foreach $thread (keys %threads) {
$tsub[$tnum] = $thread;
$tlist[$tnum] = $threads{$thread} unless $copy;
@{$tlist[$tnum]} = @{$threads{$thread}} if $copy;
$tsize[$tnum] = @{$tlist[$tnum]};
$tnum++;
}
print Dumper \@tsub,\@tlist,\@tsize;
# OUTPUT
there are more elegant ways using arrayslices but I think you should first start to understand perlref
UPDATE: Who cares, here a solution with slices (no copy)
@tsub2 = keys %threads;
@tlist2 = @threads{@tsub2};
@tsize2 = map { scalar @{$_} } @tlist2;
print Dumper \@tsub2,\@tlist2,\@tsize2;
hmmm that solution without slices is even simpler, I wasn't sure that the order of keys and values are guarantied, but it's documented so, as long as the hash isn't modified.
|