On Saturday 07 May 2005 20:56, John W. Krahn wrote:
> Gavin Henry wrote:
> > On Sunday 08 May 2005 00:13, amr wrote:
> >>How can I call the last element in the array?
> >>
> >>I try the pop and it does the job but I think there is another way?
> >
> > Of course, TMTOWTDI (http://catb.org/~esr/jargon/html/T/TMTOWTDI.html)
> >
> > $ARRAY[$#ARRAY--]
>
> Oh wow.  Did you try that?  You do realise that modifying $#ARRAY changes
> the size of @ARRAY?

Yes, this was my misunderstanding of the OP question. He wants to only find 
out what is the last element of the array and not modify it, but I gave the 
equivalent of the pop command, which your proof demonstrates.

http://perldoc.perl.org/functions/pop.html

>
> $ perl -le'
> @ARRAY = "A" .. "Z";
> print "Size: " . @ARRAY, " $ARRAY[$#ARRAY]";
> print "Size: " . @ARRAY, " $ARRAY[$#ARRAY--]";
> print "Size: " . @ARRAY, " $ARRAY[$#ARRAY--]";
> print "Size: " . @ARRAY, " $ARRAY[--$#ARRAY]";
> print "Size: " . @ARRAY, " $ARRAY[--$#ARRAY]";
> '
> Size: 26 Z
> Size: 26
> Size: 25
> Size: 24 W
> Size: 23 V
>
>
>
> John
> --
> use Perl;
> program
> fulfillment

-- 
Walking the road to enlightenment... I found a penguin and a camel on the 
way.....
Fancy a [EMAIL PROTECTED] Just ask!!!

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to