by_val does not modify its parameter ($_[0]), it modifies a copy of its parameter ($var). Without realizing it, you've used the very refactoring tool you are trying to present to us (my $var = shift;).
Using a temporary variable instead of assigning to (or even reading from) a parameter is standard practice in Perl!
Update: Example:
sub inc_original { $_[0]++; return $_[0]; } sub inc_refactored { my ($var) = @_; $var++; return $var; } { my $i = 3; my $j = inc_original($i); print("$i + 1 = $j\n"); # 4 + 1 = 4 } { my $i = 3; my $j = inc_refactored($i); print("$i + 1 = $j\n"); # 3 + 1 = 4 }
In reply to Re^3: Refactoring Perl #7 - Remove Assignments to Parameters
by ikegami
in thread Refactoring Perl #7 - Remove Assignments to Parameters
by agianni
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |