in reply to Re^2: Line numbers
in thread Line numbers
Indeed there is an advantage of the first - I can remember the syntax.
It is non-obvious why (caller(0))[2] should work but caller(0)[2] should fail.
Also, the arrayref plays nicer associativity wise. Check this out:
$ perl -E'sub x { say [caller(0)]->[0] } x()' main $ perl -E'sub x { say (caller(0))[0] } x()' syntax error at -e line 1, near ")[" Execution of -e aborted due to compilation errors.
The version with the arrayref just acts more predictably in my mind. I don't have to waste time thinking about it.
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^4: Line numbers
by chromatic (Archbishop) on Mar 17, 2012 at 00:02 UTC | |
by tobyink (Canon) on Mar 17, 2012 at 00:12 UTC | |
by chromatic (Archbishop) on Mar 17, 2012 at 00:42 UTC | |
by Anonymous Monk on Mar 17, 2012 at 00:39 UTC | |
by LanX (Saint) on Mar 17, 2012 at 01:57 UTC | |
by LanX (Saint) on Mar 17, 2012 at 00:07 UTC | |
by gg48gg (Sexton) on Mar 17, 2012 at 01:46 UTC | |
by LanX (Saint) on Mar 17, 2012 at 02:04 UTC | |
by gg48gg (Sexton) on Mar 19, 2012 at 17:42 UTC | |
by LanX (Saint) on Mar 19, 2012 at 18:22 UTC | |
| |
by Anonymous Monk on Mar 17, 2012 at 02:10 UTC | |
Re^4: Line numbers
by LanX (Saint) on Mar 17, 2012 at 00:08 UTC | |
by repellent (Priest) on Mar 17, 2012 at 06:51 UTC |
In Section
Seekers of Perl Wisdom