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 :(.