in reply to Re: Passing argument by reference (for a scalar)
in thread Passing argument by reference (for a scalar)
I think, passing a string by reference makes sense when you work with extremely large string
Please read the earlier answers which show this completely wrong. Perl always passes by reference, so there's no reason to pass a reference.
Note that COW has a chance of failing. (The scalar needs to "owned by Perl", and its string buffer must have space to accommodate the COW count.) But even if you want to give your argument names without relying on COW, you don't have to change your code to use references. Instead, you can replace
my $x = shift;
with
use experimental qw( refaliasing declared_refs ); my \$x = \shift;
or
use Data::Alias qw( alias ); alias my $x = shift;
or
our $x; local *x = \shift;
|
|---|