in reply to global $_ behavior
The code above produces test : test, which illustrates clearly what is going on. What works is to use local on $_ inside the subroutine. Like this:my $aleph = test(1,2); my $test = $_; print "$aleph : $test"; sub test { my ($a, $b) = @_; $_ = 'test'; }
This produces test : $_ is empty. Update: I forgot to mention that this is documentend in perlvar.my $aleph = test(1,2); my $test = $_ ? $_ : '$_ is empty'; print "$aleph : $test"; sub test { local $_; my ($a, $b) = (@_); $_ = 'test'; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: global $_ behavior
by verdemar (Initiate) on Dec 02, 2005 at 13:15 UTC | |
by jonadab (Parson) on Dec 02, 2005 at 14:28 UTC |