in reply to Re: Multidimensional array
in thread Multidimensional array

Indeed. The fragment offered can be fixed...

push (@Mdevices, [$UnitID, $fileno]); for ($k=0; $k<=$#Mdevices; $k++) { print $Mdevices[$k][0],"\n"; } $k=0;
...the named @Cdevices is not required.

If the more complete code is along the lines:

my @Mdevices ; my @Cdevices ; while (... something ...) { ... do something to get $UnitID & $fileno ... push (@Cdevices, $UnitID, $fileno); ... do some other stuff ... push (@Mdevices, \@Cdevices); } ;
then @Mdevices is going to end up with 'n' copies of a reference to @Cdevices, which contains a list of the 'n' $UnitID and $fileno seen.

Whereas the almost identical:

my @Mdevices ; while (... something ...) { my @Cdevices ; ... do something to get $UnitID & $fileno ... push (@Cdevices, $UnitID, $fileno); ... do some other stuff ... push (@Mdevices, \@Cdevices); } ;
fills @Mdevices with 'n' references to 'n' different annonymous arrays, each containing a $UnitID and $fileno pair.

Obvious, really.

Alternatively:

my @Mdevices ; while (... something ...) { ... do something to get $UnitID & $fileno ... ... do some other stuff ... push (@Mdevices, [$UnitID, $fileno]); } ;
will do the trick -- unless the @Cdevices array is required in the loop.

Replies are listed 'Best First'.
Re^3: Multidimensional array
by igor1212 (Novice) on Dec 10, 2008 at 19:43 UTC
    Hello!

    This code really did the trick!

    my @Mdevices ; while (... something ...) { ... do something to get $UnitID & $fileno ... ... do some other stuff ... push (@Mdevices, [$UnitID, $fileno]); } ;

    Thanks to all of you for help

    Igor