"Rob Anderson" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
>
> "Sitha Nhok" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> > Hi, if I have a multidimensional array like :
> >
> > @AoA = (
> >                  ["ABC", "BCD"],
> >                  ["CDE", "DEF"],
> >                  ["EFG", "FGH"],
> >                  );
> >
> >
> > then do:
> >
> > @var = splice @AoA, 2, 1;  # to delete the last row
> >
> > print @var; #print what was returned from splice
> >
> >
> >
> > The print statement prints an address.  I like it to print the contents
> > that was removed.  How do I do that?
> >
>
> Just to make sure you understand, when you create an array of arrays like
> this, your actually creating one top level array (ie @AoA) each element of
> which is a reference to an anonymous (created by your ["ABC...
declaration).
>
> What you're printing is the reference removed from the top level array. So
> you need to dereference it, perhaps like this...
>
> my $inner_array_ref = $var[0];
> print @$inner_array_ref;
>
> This is long winded, but explains what's going on. We take the first
element
> of the array (which we assume exists) and then print it out, put
deferencing
> it to an array by prefixing it with a @.
>
> You could also do this...
>
> my $inner_array_ref = $var[0];
> print $$inner_array_ref[1];
>
> Which will print the second element from the inner array.
>
> You'd be well advised to read up on references, and de-referencing stuff.

of course, it would have been helpful to let you know the easy way into your
array, which is just...

 print $var[0][1];

which does your deferencing for you, but where's the fun in that?


>
> HTH
>
> Rob Anderson
>
> > ~Sitha
> >
>
>



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to