my $new_string = testing_string($string);
sub testing_string {
my $content = $_[0]; #string copy, expensive
# do some stuff
$content =~ s/a/b/sg;
return $content; #string copy, expensive
}
####
# do stuff here
my %test_var;
$test_var{$string} = $string; # double!! string copy and hash
# sum calculation, expensive. And why
# this senseless copying into a hash? a scalar
# variable (i.e $string) is global too
testing_string();
$string = $test_var{$string}; # string copy and hash sum calculation of $string
sub testing_string_2 {
# do some stuff here
$test_var{$string} =~ s/a/b/sg;
}
####
testing_string(\$string); #send a reference to $string instead of $string
sub testing_string {
my $contentref = $_[0];
# do some stuff
$$contentref =~ s/a/b/sg;
}