Could there be some mistake in the copying of the code? I tested my code and it works (both versions). Here is my complete sample code. Be sure to use the download button underneath before you copy/paste the code so you don't copy word wrapped lines. And remember that for the code with the push you also need to remove the closing '}' of the loop.

#!/usr/bin/perl use warnings; %threads=('a', [1,2,3], 'b', [2,2,3], 'e', [3,2,3], 'd', [4,2,3], 'c', [5,2,3]); $tnum=0; foreach $thread (keys %threads) { print "\n thread for $thread, tnum=$tnum:"; #dbg print "\n\tthe array from hash=@{$threads{$thread}}"; #dbg # THE ABOVE LINE CORRECTLY PRINTS THE ELEMENTS OF THE ARRAY OF THE HAS $tsub[$tnum] = $thread; $tsize[$tnum] = @{$threads{$thread}}; print "\n\ttsize[tnum]= $tsize[$tnum]"; #dbg # for ($i=0; $i<$tsize[$tnum] ; $i++) # { $tlist[$tnum][$i] = $threads{$thread}[$i]; push( @{$tlist[$tnum]}, @{$threads{$thread}} ); # HERE I'M TRYING TO PRINT THE ELEMENTS ONE AT A TIME print "\n\t\@{threads{thread}}=@{$threads{$thread}}"; # BUT THE ABOVE LINE PRINTS ONLY A NULL }

which gives me the following output (note that as LanX found out you don't increment tnum, so there is still a bug in this code):

Name "main::tsub" used only once: possible typo at ./t7.pl line 17. Name "main::tlist" used only once: possible typo at ./t7.pl line 22. thread for e, tnum=0: the array from hash=3 2 3 tsize[tnum]= 3 {threads{thread[0]}}=3 2 3 thread for c, tnum=0: the array from hash=5 2 3 tsize[tnum]= 3 {threads{thread[0]}}=5 2 3 thread for a, tnum=0: the array from hash=1 2 3 tsize[tnum]= 3 {threads{thread[0]}}=1 2 3 thread for b, tnum=0: the array from hash=2 2 3 tsize[tnum]= 3 {threads{thread[0]}}=2 2 3 thread for d, tnum=0: the array from hash=4 2 3 tsize[tnum]= 3 {threads{thread[0]}}=4 2 3

In reply to Re^3: syntax of multidimensional arrays and hashes by jethro
in thread syntax of multidimensional arrays and hashes by hsfrey

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.