Fellow monks,
I'm working on a subroutine that I want to pass a bareword as parameter. While doing that, I stumbled upon a weird problem. Let's take this program
use strict; use warnings; sub sub1(*) { print "args(1): @_\n"; sub2(@_); } sub sub2(*) { print "args(2): @_\n"; } sub sub3(*) { print "args(3): @_\n"; sub2(@_); } sub1 Bareword; sub3 Bareword;
and run it. What would you expect is it's output? My expectation was
args(1): Bareword args(2): Bareword args(3): Bareword args(2): Bareword
What was actually printed by the program is
args(1): Bareword args(2): Bareword args(3): Bareword args(2): 1
Can any of the more enlightened monks explain to me why that happens? Obviously, it seems to be caused by the order of definition of the subroutines, but why? This is on v5.8.1-RC3 on Mac OS X 10.3.3, by the way.
In reply to Stumped when passing barewords by crenz
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |