Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Where was I called?

by BrowserUk (Pope)
on Sep 28, 2006 at 12:54 UTC ( #575341=note: print w/replies, xml ) Need Help??


in reply to Where was I called?

Presumably this is for some kind of error reporting? How about simply reformatting the source code as:

for ( 1 .. 10 ) { my ( $foo, $bar ) = ( some_sub(), some_sub() ); # do stuff }

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: Where was I called?
by Ovid (Cardinal) on Sep 28, 2006 at 13:26 UTC

    That's one thought, but it turns out there's a bug in the scheme.

    while ( my $value = some_sub() ) { # line 50 my $next_value = some_sub(); # line 51 }

    This is something I forgot about, but it's very, very irritating. The first time some_sub() is called, caller will correctly report that line 50 is the calling line and the second time some_sub() is called, it reports line 51. However, the second time through the while loop, the first some_sub() is reported as being on line 51! That totally blows my initial scheme.

    Cheers,
    Ovid

    New address of my CGI Course.

      Wow, thanks Ovid! I never realized that problem existed. Just to explain, whenever a nextstate op is seen the global variable PL_curcop is set and that's some of what caller() uses. You know line 50 as you enter the loop, then the first line in the loop is 51 but you never reach that outer nextstate op to say you're testing a condition on line 50 again. I bet if you were really interested in solving this problem in a JFDI way that you could change that "goto 9" to be "goto 2" or promote the conditional expression into a do{} block. But that way lies madness so you won't do that.

      ### caller() will report line 50. 2 <;> nextstate(main 2 x:50) v 3 <{> enterloop(next->8 last->d redo->4) v 9 <0> pushmark s a <#> gv[*X] s/EARLYCV b <1> entersub[t2] sKS/TARG,1 c <|> and(other->4) vK/1 ### caller() will report line 51 4 <;> nextstate(main 1 x:51) v 5 <0> pushmark s 6 <#> gv[*Y] s/EARLYCV 7 <1> entersub[t4] vKS/TARG,1 8 <0> unstack v goto 9 d <2> leaveloop vK/2 e <@> leave[1 ref] vKP/REFC

      ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

        You know, that almost made sense to me. OK, no it didn't. I have no idea how to read that output :) The reason why caller gets it wrong now seems to make sense, though, so thanks!

        Cheers,
        Ovid

        New address of my CGI Course.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (8)
As of 2021-06-25 10:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)












    Results (135 votes). Check out past polls.

    Notices?