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'