Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: caller() returns wrong line on multi-line function call

by ikegami (Pope)
on Sep 14, 2017 at 00:05 UTC ( #1199362=note: print w/replies, xml ) Need Help??


in reply to caller() returns wrong line on multi-line function call

At the start of each statement is a nextstate op which sets the current line number. Remember that %{{ A => 1, B => 2, C => 3 }} use the %BLOCK syntax and BLOCK contains a sequence of statements.

Replies are listed 'Best First'.
Re^2: caller() returns wrong line on multi-line function call (blocks)
by LanX (Bishop) on Sep 14, 2017 at 13:17 UTC
    > Remember that %{{ A => 1, B => 2, C => 3 }} use the %BLOCK syntax and BLOCK contains a sequence of statements.

    I had problems to see why dereferencing should be implemented with a block syntax, but indeed one is free to include any statement inside %{...} as long as it can't be confused with a variable

    for instance

    DB<2> print %{ ( do{ {A=>1} } ) } A1

    Actually the problem is not restricted to dereferencing. other block syntax is having the same impact of messing up "nextstate".

    Like this

    print_calling_line( __LINE__, do { A => 1, B => 2, C => 3 } );

    will report the line of the do statement.

    Cheers Rolf
    (addicted to the Perl Programming Language and ☆☆☆☆ :)
    Je suis Charlie!

    update

    actually the line of the last block will be reported

    print_calling_line( __LINE__, do { A => 1, B => 2, C => 3 }, do { A => 1, B => 2, C => 3 }, do { A => 1, B => 2, C => 3 } ); ... Called from line 27; caller() reports line 30

    looks like the line number is stored inside a localized variable in C and overwritten while parsing following blocks.

      It looks like some block statements report the line the block begins—dereferences, as in my OP, as well as calls to do and eval (block style only!)—but others, notably inline creation of an anonymous subroutine with sub { }, report the line after the block (???). I haven't messed around with the decompiler, but I assume this has to do with where the nextstate elements get placed.

      Example:

        > report the line after the block (???).

        ugh ... oO

        I'm pretty sure there is some global variable supposed to hold the line number getting overwritten while descending the arguments tree.

        Cheers Rolf
        (addicted to the Perl Programming Language and ☆☆☆☆ :)
        Je suis Charlie!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1199362]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2017-11-25 06:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (355 votes). Check out past polls.

    Notices?