in reply to hash of arrays to array of arrays

What are you trying to do in this line:
@tlist[$tnum] = @{$threadds{$thread};

Can you give an example of the input you have and the output you expect?

Replies are listed 'Best First'.
Re^2: hash of arrays to array of arrays
by spazm (Monk) on Jul 16, 2009 at 20:23 UTC
    Ok, I think I see what you're trying to do.

    1. walk through threads
    2. each key in threads points to an array ref
    3. store each arrayref into an array

    modifying your code without munging it too much, I change to storing the array ref in $tlist[$tnum]; And then when we access from $tlist, we dereference into the array.

    The syntax you had @tlist[$i] was actually doing an array slice.

    print "\n\nThe Hash Table\n\n"; foreach $thread (keys %threads) { print "$thread: @{$threads{$thread}}\n"; } #this prints out lines like: #keyA: 2 6 8 #keyB: 3 5 10 14 18 #etc. # Convert hash table into arrays for Threads, with common index $tnum $tnum=0; foreach $thread (keys %threads) { $tsub[$tnum] = $thread; $tlist[$tnum] = $threads{$thread}; #store the array reference. $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]"; }