Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: parm#4 from caller == !"eval" ?

by perl-diddler (Hermit)
on Sep 12, 2017 at 22:30 UTC ( #1199236=perlquestion: print w/replies, xml ) Need Help??
perl-diddler has asked for the wisdom of the Perl Monks concerning the following question:

Was looking at output from caller EXPR and from my testing, I was surprised by param number 4 (from 0) called $hasargs being "1" when the sub it was in had no arguments (or parameters).

In reading the explanation for the parameter $hasargs, it seems it might be better named $newframe or such -- not that such a name is more clear (without explanatory text), but at least no one would mistake it for meaning the sub it is called in had arguments.

It seems that it is not 1, only when the subroutine parameter is (eval).
Is that true?
Does anyone know if there are other situations where $hasargs is not '1'?

Would it be worthwhile to file a doc-bug against the manpage(perdoc) to have it renamed to something other than $hasargs, so it won't confuse people into thinking it means that the called subroutine, it is in, "has arguments" (because that's not what it means), but instead might be called $hasframe, $newframe or something that would better describe what it is or, at least, not cause confusion?

Replies are listed 'Best First'.
Re^2: parm#4 from caller == !"eval" ?
by choroba (Bishop) on Sep 12, 2017 at 22:50 UTC
    The documentation says:

    $hasargs is true if a new instance of @_ was set up for the frame.

    And that's how it works:

    sub x1 { @_ = 'a'; &x2 } sub x2 { my ($c) = @_; say $c, (caller 0)[4] } x2('b'); # b1 x1(); # a

    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
      Addendum to explain what the &x2 call does

      > Subroutines may be called recursively. If a subroutine is called using the & form, the argument list is optional, and if omitted, no @_ array is set up for the subroutine: the @_ array at the time of the call is visible to subroutine instead. This is an efficiency mechanism that new users may wish to avoid.

      Source perlsub

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

        To you and choroba, thanks for the example(s). I completely forgot about the '&' case.

        Thanks!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1199236]
Approved by choroba
Front-paged by LanX
help
Chatterbox?
[1nickt]: Discipulus I was sleeping in :-) It's a Holyday here. No work today. Just eating. Enjoy your day everymonk!

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













    Results (336 votes). Check out past polls.

    Notices?