Here's a snippet of the code. What you'll see is that I can print data from my foreach pull, but I'm not able to push it to a multidimensional array:
$qry = $DB->Query("SELECT * FROM recipes WHERE type = '$type' ORDER +BY rand() limit $quantity") || die "Got error on select: $Mysql::db_errstr\n"; + for ($i=0; $i<$qry->numrows; $i++) { @row = $qry->fetchrow or warn "recipes didn't find a matching row" +; print "\@row is assigned @row\n"; $j = 0; foreach my $bug (@row) { @athlete[$i,$j++] = $bug ; print "\$i\$j is assigned $i:$j\n"; print "\@athlete[\$i,\$j] is assigned the value @athlete[$i,$j]\ +n"; print "\$bug is assigned the value $bug\n"; } } }
@row is assigned 33 Small Bunch Grapes carb 15 0.4 0.1 $i$j is assigned 4:1 @athlete[$i,$j] is assigned the value 33 $bug is assigned the value 33 $i$j is assigned 4:2 @athlete[$i,$j] is assigned the value Small Bunch Grapes $bug is assigned the value Small Bunch Grapes $i$j is assigned 4:3 @athlete[$i,$j] is assigned the value carb 0.2 $bug is assigned the value carb $i$j is assigned 4:4 @athlete[$i,$j] is assigned the value 15 15 $bug is assigned the value 15 $i$j is assigned 4:5 @athlete[$i,$j] is assigned the value $bug is assigned the value 0.4 $i$j is assigned 4:6 @athlete[$i,$j] is assigned the value 0.1 $bug is assigned the value 0.1
Particuarly, $bug is able to receive 0.4 from the foreach, but the attempt to assign it to fifth element of the fourth row of the Athlete array was unsuccessful. Perl doesn't cough on this problem, it just troops along. Any ideas?

In reply to Where is my foreach data going to? by brotherdaniel

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.