Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^5: Line numbers

by tobyink (Canon)
on Mar 17, 2012 at 00:12 UTC ( #960098=note: print w/replies, xml ) Need Help??


in reply to Re^4: Line numbers
in thread Line numbers

That there exists an explanation does not imply that the explanation is obvious.

I understand that light may act as a wave or particle depending on how you study it. However, this fact is not obvious. It is in fact incredibly non-obvious, which is how it took science so long to get there.

That [caller(0)]->[0] works is (at least to me) obvious. That (caller(0))[0] works and caller(0)[0] fails is (again, to me) non-obvious.

perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

Replies are listed 'Best First'.
Re^6: Line numbers
by chromatic (Archbishop) on Mar 17, 2012 at 00:42 UTC
    I understand that light may act as a wave or particle depending on how you study it.

    Certainly, but unlike particle physics, Perl comes with a manual.

    I'm not claiming that slicing the list returned from a function has syntax that's immediately obvious to everyone, but it's not that obscure once you understand Perl's precedence.

Re^6: Line numbers
by Anonymous Monk on Mar 17, 2012 at 00:39 UTC
    So you exchange parens for square brackets and add an arrow instead. Sorry, but you really haven't proven your point. They are both non-obvious until you understand how Perl handles precedence and lists. caller(0)[0] fails because you are trying to index a scalar, not a list.
      > fails because you are trying to index a scalar

      No,it fails because it's undefined syntax

      syntax error ... near ")["

      and indexing a list always requires parens!

      see perldata

      A list value may also be subscripted like a normal array. You must +put the list in parentheses to avoid ambiguity.

      Cheers Rolf

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (1)
As of 2022-01-25 23:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (69 votes). Check out past polls.

    Notices?