Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

phantom subroutine parameter values

by rpelak (Sexton)
on Apr 15, 2008 at 02:53 UTC ( #680420=perlquestion: print w/ replies, xml ) Need Help??
rpelak has asked for the wisdom of the Perl Monks concerning the following question:

So I swear I have seen this before... But I can't remember under what conditions it happens, so I can't avoid it.

I have a sub for which all parameters are optional. And sometimes... when I call it with no parameters, the parameters of the proc it was called from show up as it's parameters...

Anyone know under what circumstances this happens, and of course how to avoid it from happening?

rpelak

Comment on phantom subroutine parameter values
Re: phantom subroutine parameter values
by GrandFather (Cardinal) on Apr 15, 2008 at 03:06 UTC

    Most likely you are using & to call the sub: &subToBeCalled. Don't do that! ;)


    Perl is environmentally friendly - it saves trees
Re: phantom subroutine parameter values
by blahblahblah (Priest) on Apr 15, 2008 at 03:08 UTC
    This will happen when you call a sub with an ampersand but without any parentheses, like the following:

    ⊂

    Doing so makes the calling sub's @_ visible to called subroutine. To avoid this, either omit the ampersand or include empty parens when calling a sub with no args. See perlsub for more info.

      Thanks guys. I knew it was something simple... That explains why a lot of my old code doesn't have ampersands... Sucks be forced to program in tcl for a few years... rpelak
        uh?! it seems a feature! in any case i like calling with the & 'cause i spot easy subroutine's calling.

        if i understand :
        sub refinemydata { my $data = shift; &is_refined:return?&rerefine;}
        could be a valid syntax too ?
        something new

        Lor*

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (13)
As of 2014-07-23 12:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (141 votes), past polls