Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re: Answer: How do I find the index of the last element in an array?

by jens (Pilgrim)
on Oct 14, 2002 at 04:30 UTC ( #204971=note: print w/replies, xml ) Need Help??

in reply to Answer: How do I find the index of the last element in an array?
in thread arrays

Hmm....actually, that doesn't really help at all!

If you want to know the index of the last element of an array, do this:

@letterList = ("a", "b", "c", "d"); #refer to the last array index #using '$#array' syntax: print $#letterList;
This will, of course, output "3".

You can also refer to the value of the last element of the array
using negative indices, e.g. $letterList[-1] will also refer to "d".

Microsoft delendum est.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://204971]
[MidLifeXis]: Nothing like encouraging the success of a rollout by neutering your current support structure without a reasonable staffed and trained replacement structure.
[MidLifeXis]: Speaking of which, anyone know of Perl positions in the MKE area (or slightly west)?
[Corion]: MidLifeXis: Oh, enjoying the show from the sidelines I see...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (11)
As of 2017-03-23 12:31 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (286 votes). Check out past polls.