Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

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


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?

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (8)
As of 2015-11-29 20:19 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (753 votes), past polls