Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

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
[Corion]: And so far I like signatures and nobody has yet come up to me and screamed at me for implementing a source filter to handle them even on early Perl versions ;)
[Corion]: I should re-prod tsee about the Filter::Simple branches that he might want to merge or that I should merge so he can do a release ;-D

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (9)
As of 2017-02-27 14:44 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (388 votes). Check out past polls.