Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Re: Stumped when passing barewords

by Fletch (Chancellor)
on Apr 22, 2004 at 13:23 UTC ( #347342=note: print w/ replies, xml ) Need Help??


in reply to Re: Stumped when passing barewords
in thread Stumped when passing barewords

Yes, if you read perlsub on prototypes carefully it would appear that "*" forces scalar context in the same way that "$" would. Might be worth someone working up an extra sentence which makes an explicit mention of the fact and submitting a patch to p5p.

Update: And I've just submitted said doc patch.

Replies are listed 'Best First'.
Scalar context changes bareword value?
by crenz (Priest) on Apr 22, 2004 at 13:27 UTC

    broquaint, thanks for the research. It seems you found the phenomenon causing the problem.

    Fletch, I would expect for the bareword to stay the same, even in scalar context. If I change sub 1 to

    sub sub1(*) { print "args(1): @_\n"; print scalar $_[0], "\n"; sub2(@_); }

    the second value printed is Bareword and not 1.

    So am I misunderstanding the spec here, or is it a bug?

      The bareword is the same in scalar context, however the array @_ in scalar context is another matter. @_ itself hasn't changed, but when you pass it to sub2 it's put in scalar context ("*" is behaving similarly to "$" in this case).

        Thanks for the explanation! I can just pass $_[0] in this situation, which should make it work. However, if there would be multiple parameters and I wanted to pass @_ as a whole, there'd be a problem :(.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (12)
As of 2016-07-27 19:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What is your favorite alternate name for a (specific) keyboard key?


















    Results (247 votes). Check out past polls.