Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re^5: Line numbers

by gg48gg (Sexton)
on Mar 17, 2012 at 01:46 UTC ( #960108=note: print w/replies, xml ) Need Help??

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

Right. The added complexity actually comes from introducing the say function, which takes a list.

say (caller(0))[0];

is expanding to:

say $package, $filename, $line, $subroutine, $hasargs,$wantarray, $eva +ltext, $is_require, $hints, $bitmask, $hinthash,[0];

This gives you the syntax error:

say [0];

Replies are listed 'Best First'.
Re^6: Line numbers
by LanX (Sage) on Mar 17, 2012 at 02:04 UTC
    > is expanding to:

    > say $package, $filename, $line, $subroutine, $hasargs,$wantarray, $evaltext, $is +_require, $hints, $bitmask, $hinthash,[0];

    nope, and you're showing valid code! After the last comma comes a literal arrayref [0].

    DB<100> print $a,[0]; ARRAY(0x84e16b8)

    the syntax-error comes from appending [0] unseparated to a function call say().

    and nothing is "expanded" at parsing time.

    Cheers Rolf

      Thanks for setting me straight Rolf. I was getting an error because I didn't have the say feature enabled. I guess I shouldn't have stated it so matter-of-fact. I was so sure I had it figured out.

      I am still a little confused about this and why anonymous' code works...

      print '', (caller(0))[0];

      and why this gets a syntax error:

      print (caller(0))[0];
        Because parens around sub-args are optional.

        print '', (caller(0))[0]; means print ( '', (caller(0))[0] );

        But providing explicit parens after a sub-name will disable automatic grouping of args.

        Cheers Rolf

Re^6: Line numbers
by Anonymous Monk on Mar 17, 2012 at 02:10 UTC
    Actually, this is wrong!
    When you say: print (caller(0))[0], print is interpretated as a function (equaivalent to print('hi')[0]), but it works fine if you say: print '', (caller(0))[0]

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (4)
As of 2022-01-23 03:46 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (63 votes). Check out past polls.