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

Re: Where is $# fully documented?

by ysth (Canon)
on Sep 23, 2014 at 14:24 UTC ( #1101646=note: print w/replies, xml ) Need Help??


in reply to Where is $# fully documented?

The documentation for using references is at http://perldoc.perl.org/perlref.html#Using-References. It does not mention $# at all, but points 1 and 2 there address exactly what you are asking about. In general, the documentation does not strive to cover every possible combination of interacting features.

--
A math joke: r = | |csc(θ)|+|sec(θ)| |-| |csc(θ)|-|sec(θ)| |

Replies are listed 'Best First'.
Re^2: Where is $# fully documented?
by LanX (Archbishop) on Sep 23, 2014 at 14:44 UTC
    > It does not mention $# at all

    well in these 5.20 docs this is mentioned  $aref->$#*; # same as $#{ $aref }

    > but points 1 and 2 there address exactly what you are asking about.

    Anywhere you'd put an identifier (or chain of identifiers) as part of a variable or subroutine name

    So I suppose $# counts as a special function since its not a variable, but addressing an attribute of a variable?

    Thanks anyway! :)

    Cheers Rolf

    (addicted to the Perl Programming Language and ☆☆☆☆ :)

      Special function? No.

      The a in @a is the identifier part of the variable name; the documentation addresses anywhere you'd put that a, which includes $#a.

      Update: hmm, it does say "as part of a variable...name", implying it would only work if $#a is a considered a variable. I shy away from that because, even though it is an assignable lvalue, it really is just an attribute of an array variable. So the doc could use a minor tweak.

      In any case, $#$arrayref / $#{$arrayref} ought to be added to the examples there.

      --
      A math joke: r = | |csc(θ)|+|sec(θ)| |-| |csc(θ)|-|sec(θ)| |
        > I shy away from that because, even though it is an assignable lvalue, it really is just an attribute of an array variable. So the doc could use a minor tweak.

        That's my point, I couldn't mentally map this behavior to normal dereferencing mechanics cause it rather feels like a magic feature.

        To make it more obvious, theoretically we could have a special syntax for keys and values of a hash ( like e.g. %<hash ).

        This would be a similar beast (/me struggling for a name ;)

        > In any case, $#$arrayref / $#{$arrayref}ought to be added to the examples there

        Definitely!

        Cheers Rolf

        (addicted to the Perl Programming Language and ☆☆☆☆ :)

      $#a is no more a function and as much a variable as $a and @a.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2019-11-18 11:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Strict and warnings: which comes first?



    Results (89 votes). Check out past polls.

    Notices?