Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: how internally $#array is working in Perl

by sflitman (Hermit)
on Aug 13, 2010 at 05:44 UTC ( #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
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
Node Status?
node history
Node Type: note [id://854833]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (11)
As of 2014-11-26 17:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (172 votes), past polls