in reply to Should chomping a constant always raise an error?
sub modify { chomp( $_[0] ); # whatever else happens, you've just potentially modified $_[0] } modify('fred'); # What would you expect to happen to 'fred'? my $f ="fred\n"; modify($f); print $f; #fred
sub modify2 { # Create a copy of the input my $input = $_[0]; chomp($input); } modify('fred'); # works now because we're not modifying the input, but a copy of it. my $f ="fred\n"; modify($f); print $f; #fred\n
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: can this be turned into a compile-time error?
by Thilosophy (Curate) on Mar 11, 2005 at 03:56 UTC | |
by QM (Parson) on Mar 11, 2005 at 18:54 UTC |