I am asking this question out of curiosity. Since Perl string is value type, does passing long string as subroutine argument incur performance penalty? I searched around and found that since perl 5.20 (http://perldoc.perl.org/5.20.0/perldelta.html#Performance-Enhancements), Does that mean perl <5.20 will suffer if long strings are passed around? (especially argument is used as read-only)
Perl has a new copy-on-write mechanism that avoids the need to copy the internal string buffer when assigning from one scalar to another. This makes copying large strings appear much faster. Modifying one of the two (or more) strings after an assignment will force a copy internally. This makes it unnecessary to pass strings by reference for efficiency.
# perl string is value type (not reference) my $s = "foo"; my $t = $s; $s .= "bar"; # $t is still 'foo' since assignment copy the value.
In reply to perl string pass by value by pwagyi
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |