[ale] Perl question on Arrays

Fletch fletch at phydeaux.org
Sat Jun 12 19:27:06 EDT 2004


>>>>> "Josh" == Josh Freeman <josh at catea.org> writes:

    Josh> I have two arrays that are both two dimensional. I assign
    Josh> @foo=[some][multidimensional][array];

Arrays in perl are always one dimensional.  You have an array which
contains references to arrays.</pedant>

If you want to get out a lower level array, you just use @{} to
dereference the apropriate arrayref.

@foo = @{ $bar->[23]->[42] };


Keep in mind that this makes a copy of the contents of the array
referenced by what's in $bar->[23]->[42] and modifying (say) $foo[0]
will not do anything to $bar->[23]->[42]->[0] (to do that you'd want
to instead do: $foo = $bar->[23]->[42]; $foo->[0] += 17).


See perldoc perlreftut, perldoc perllol, and perldoc perldsc.

-- 
Fletch                | "If you find my answers frightening,       __`'/|
fletch at phydeaux.org   |  Vincent, you should cease askin'          \ o.O'
                      |  scary questions." -- Jules                =(___)=
                      |                                               U



More information about the Ale mailing list