in reply to lhs substr(): refs vs. scalars
Perl is not really pass-by value - the stuff in @_ are (aliases to) the actual variables you pass in, not copies:
sub foo_ize { for my $val (@_) { $val =~ s!bar!foo!gi; }; }; my @arr = qw( baz bar baz BarBar ); foo_ize @arr; print join ",", @arr;
The "pass by value" comes into effect once you employ the standard practice of copying your parameters:
sub foo_ize_val { my @args = @_; map { s!foo!bar!ig; $_ } @args; }; my @arr = qw( baz bar baz BarBar ); foo_ize @arr; print join ",", @arr; @arr = foo_ize @arr; print join ",", @arr;
|
|---|