in reply to Using eval to build array structure

Let's fix the base problem, so you don't have to even think about eval at all.
use strict; my @gameboard = ( [ 1, 2, 3, 4, 5 ], [ 2, 3, 4, 5, 1 ], [ 3, 4, 5, 1, 2 ], [ 4, 5, 1, 2, 3 ], [ 5, 1, 2, 3, 4 ], ); for my $i (1 .. 4) { for my $j ($i + 1 .. 5) { if ($gameboard[$i][0] == $gameboard[$j][0]) { print "Matched $i,0 and $j,0\n"; } } }

These are called array references. It's the way Perl (from 5.000 onwards) does multi-level data structures. Read up on them - they'll make your life very easy.

------
We are the carpenters and bricklayers of the Information Age.

Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

Replies are listed 'Best First'.
Re(2): Using eval to build array structure
by meta4 (Monk) on Jul 17, 2002 at 17:20 UTC

    I agree with both Tye and dragonchild. However, I have just a little nit with both of their sample codes. The Range for the $i subsrcript should be 0 .. 4 since perl arrays are zero indexed.

    so,

    for my $i (1 .. 4) {
    should be
    for my $i (0 .. 4) {

    and,

    for $j($i+1..5){
    should be
    for $j($i+1..4){

    -meta4
      I would agree with you, yes, that arrays do start from 0 in Perl. However what I was originally trying to do was to get @array1, @array2, etc. build using the loop index. Since my arrays were numbered 1-5, they are correct in their examples ( at least for my problem ).

      Some people fall from grace. I prefer a running start...