Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

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
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (6)
As of 2017-11-24 11:34 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (348 votes). Check out past polls.