in reply to a MooseX Q that's driving me up the wall :)
sub f { 'xxx' =~ /(.*)/; print("$_[0]\n"); } 'aaa' =~ /(.*)/; f($1); # xxx 'aaa' =~ /(.*)/; f("$1"); # aaa
Perl passes arguments by reference, not by value. You are passing a global variable, and the global variable gets changed the by the called function before the argument is used. Passing a copy of the global avoids the problem.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: a MooseX Q that's driving me up the wall :)
by tj_thompson (Monk) on Dec 03, 2010 at 17:06 UTC | |
by ikegami (Patriarch) on Dec 03, 2010 at 17:14 UTC | |
by tj_thompson (Monk) on Dec 03, 2010 at 18:47 UTC | |
|
Re^2: a MooseX Q that's driving me up the wall :)
by Anonymous Monk on Dec 03, 2010 at 17:11 UTC |