in reply to Where is my foreach data going to?

Looking at your code ...
@athlete[$i,$j++] = $bug ;
Is actually an array slice. You probably wanted this instead:
$athlete[$i,$j++] = $bug;
It's pretty easy to mistake array slices for array indices.

Replies are listed 'Best First'.
Re: Where is my foreach data going to?
by Abigail-II (Bishop) on Sep 18, 2003 at 09:52 UTC
    Did you try running
    $athlete[$i,$j++] = $bug;
    with warnings on? It doesn't mean at all what you thing it means.
    $ perl -wcle '$i = $j = 0; $athlete [$i, $j ++] = 1' Multidimensional syntax $athlete [$i, $j ++] not supported at -e l +ine 1. Useless use of a variable in void context at -e line 1. Name "main::athlete" used only once: possible typo at -e line 1. -e syntax OK

    If you want to use multi-dimensional arrays, you have to use the correct syntax:

    $athlete [$i] [$j ++] = $bug;

    Abigail

Re: Re: Where is my foreach data going to?
by brotherdaniel (Novice) on Sep 18, 2003 at 01:08 UTC
    Your change yielded these results:
    @athlete[$i,$j] is assigned the value 0.4 Small Bunch Grapes $bug is assigned the value 32 $i$j is assigned 4:2 @athlete[$i,$j] is assigned the value 0.4 carb $bug is assigned the value Medium Pear $i$j is assigned 4:3 @athlete[$i,$j] is assigned the value 0.4 15 $bug is assigned the value carb $i$j is assigned 4:4 @athlete[$i,$j] is assigned the value 0.4 0.4 $bug is assigned the value 16 $i$j is assigned 4:5 @athlete[$i,$j] is assigned the value 0.5 0.1 $bug is assigned the value 0.5 $i$j is assigned 4:6 @athlete[$i,$j] is assigned the value 0.5 $bug is assigned the value 0.2
    To be honest, I'm more confused now than I was when I first made this post.
      You need to replace all @athlete[$i,$j] with $athlete[$i,$j], even with your print statement. Because the syntax @athelete[$i,$j] is wrong. ;-)

      To understand why, you need to understand what is an array slice ...