Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

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?


Replies are listed 'Best First'.
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

Re: phantom subroutine parameter values
by GrandFather (Sage) 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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://680420]
Approved by GrandFather
[choroba]: Moose setter

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (9)
As of 2017-05-24 07:39 GMT
Find Nodes?
    Voting Booth?