Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: array problem

by Nevtlathiel (Friar)
on Mar 02, 2005 at 11:20 UTC ( [id://435768]=note: print w/replies, xml ) Need Help??


in reply to array problem

$#array_name can be used to find the length of an array, @array_name, but I'm not entirely sure how you're going to be getting at the array so I can't really be more helpful than that

Update: As Taulmarill rightly points out this isn't strictly the length of the array, but the index of the last element, which is normally one less than the length of the array since they are zero-indexed (ie the first element of the array has index 0, not 1 as you might expect), but you might find this useful as well :)

Replies are listed 'Best First'.
Re^2: array problem
by Taulmarill (Deacon) on Mar 02, 2005 at 12:07 UTC
    this is not realy true. you get the number of elements of an array by setting the array in scalar context. $#array gives you the the position of the last array element, which is mostly not the same.
    to get the size of a nested array, you have to understand references and how perl handles lists of lists. for the lazy, here is an example.

    print scalar @{$foo{key1}->[0]}, "\n";

    for those who want to know whats going on, start by reading perlreftut, perldsc and perllol.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://435768]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-04-16 18:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found