in reply to Re: Multidimensional array
in thread Multidimensional array
Indeed. The fragment offered can be fixed...
...the named @Cdevices is not required.push (@Mdevices, [$UnitID, $fileno]); for ($k=0; $k<=$#Mdevices; $k++) { print $Mdevices[$k][0],"\n"; } $k=0;
If the more complete code is along the lines:
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.my @Mdevices ; my @Cdevices ; while (... something ...) { ... do something to get $UnitID & $fileno ... push (@Cdevices, $UnitID, $fileno); ... do some other stuff ... push (@Mdevices, \@Cdevices); } ;
Whereas the almost identical:
fills @Mdevices with 'n' references to 'n' different annonymous arrays, each containing a $UnitID and $fileno pair.my @Mdevices ; while (... something ...) { my @Cdevices ; ... do something to get $UnitID & $fileno ... push (@Cdevices, $UnitID, $fileno); ... do some other stuff ... push (@Mdevices, \@Cdevices); } ;
Obvious, really.
Alternatively:
will do the trick -- unless the @Cdevices array is required in the loop.my @Mdevices ; while (... something ...) { ... do something to get $UnitID & $fileno ... ... do some other stuff ... push (@Mdevices, [$UnitID, $fileno]); } ;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Multidimensional array
by igor1212 (Novice) on Dec 10, 2008 at 19:43 UTC |