in reply to Re: sub that sets $_
in thread sub that sets $_
Don't forget to use local $_ before while ( $_ = $reader->chunk ) {, or you might clobber something without even realizing it. For example, the following snippet replaces the content of @array with false values because $_ is (in turn) a reference to each element of @array:
foreach (@array) { ... my $reader = ...; ... while ($_ = $reader->chunk) { ... } ... }
The following dies with the run-time error "Modification of a read-only value attempted":
for ('a', 'b') { ... my $reader = ...; ... while ($_ = $reader->chunk) { ... } ... }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: sub that sets $_
by tlm (Prior) on Jun 28, 2005 at 15:32 UTC |