Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: how internally $#array is working in Perl

by sflitman (Hermit)
on Aug 13, 2010 at 05:44 UTC ( [id://854833]=note: print w/replies, xml ) Need Help??


in reply to how internally $#array is working in Perl

My understanding is that $#x is the n-1 index for a 0-based array. All Perl arrays are 0-based, until you change $[. Why do you wish to change $[? Also, it may be safer to use scalar(@x) for how many elements there are in x. There are ominous warnings about $# going away at some point in several of the perldocs.

As for the actual internals, you would need to look at the Perl source. (shiver) --> perlguts

HTH,
SSF

  • Comment on Re: how internally $#array is working in Perl

Replies are listed 'Best First'.
Re^2: how internally $#array is working in Perl
by DrHyde (Prior) on Aug 13, 2010 at 10:02 UTC

    $#array is the index of the last element in the array. Perl obviously knows how many elements there are in an array - if it didn't, then it wouldn't be able to automagically grow the array as you add more stuff to it and you'd have to handle memory allocation yourself. And perl obviously knows the index of the first element, which is the value in $[. Knowing how big the array is and the starting index, calculating the last index is trivial.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2024-04-24 21:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found