hsfrey has asked for the wisdom of the Perl Monks concerning the following question:
I'm sure I've made a simple noobie syntax error. Can anyone help me find it?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}}; $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]"; } The printout reveals several errors: The $tsize[$i] field, instead of showing the number of items in the ar +ray, gives the first item of the array, and the @tlist[$i]field, instead of printing all the items of the @tlist a +rray, prints only the first. So the output now looks like: #keyA: 2, 2 #keyB: 3, 3 #etc.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: hash of arrays to array of arrays
by psini (Deacon) on Jul 16, 2009 at 20:16 UTC | |
|
Re: hash of arrays to array of arrays
by jwkrahn (Abbot) on Jul 16, 2009 at 20:34 UTC | |
|
Re: hash of arrays to array of arrays
by LanX (Saint) on Jul 16, 2009 at 20:25 UTC | |
|
Re: hash of arrays to array of arrays
by spazm (Monk) on Jul 16, 2009 at 20:14 UTC | |
by spazm (Monk) on Jul 16, 2009 at 20:23 UTC | |
|
Re: hash of arrays to array of arrays
by goibhniu (Hermit) on Jul 17, 2009 at 14:47 UTC | |
|
Re: hash of arrays to array of arrays
by hda (Chaplain) on Jul 16, 2009 at 20:56 UTC |