Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^2: perl string pass by value

by pwagyi (Monk)
on Apr 03, 2018 at 06:01 UTC ( [id://1212225] : note . print w/replies, xml ) Need Help??


in reply to Re: perl string pass by value
in thread perl string pass by value

Good point on @_ is alias entity. Unfortunately, when sub argument is supposed to be hash, example in a typical subroutine call like this, callee will *unpack* the arguments, and copying is un-avoidable. I have millions of such kind of calls. I've yet to benchmark perl <5.20 and 5.20+. If someone had already made a study on this, it'd be good to know if there's a big performance difference.

Foo->new( arg1=> $a_very_long_string, arg2 => $float, arg3=> $another_ +long_string); # in new sub new { my ($class,%args) = @_; }

Replies are listed 'Best First'.
Re^3: perl string pass by value
by davido (Cardinal) on Apr 03, 2018 at 06:12 UTC

    Yes, that was an unfortunate design decision when this could have avoided the issue:

    sub new { my ($class, $args_href) = @_; .... }

    Dave