On Saturday 07 May 2005 23:05, Peter Rabbitson wrote:
> On Sat, May 07, 2005 at 04:13:12PM -0700, 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?
>
> If
>       my @a = (1, 2, 3, 4);
> then:
>
>       my $last = pop @a;
> is the same as
>       my $last = $a[-1];

Doh, I completely forgot that one.

>
> and
>
>       pop @a;
>       my $third = pop @a;
> is the same as
>       my $third = $a[-2];
>
> The negative sign in front of N means go N positions towards the start of
> the array from the end.
>
> Peter

-- 
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