use strict;
sub modifyString
{
my @param=@_;
foreach (@param)
{
$_ =~ s/aaa/bbb/;
print "param member =$_\n";
}
print "param[0] out of loop=$param[0], foreach directly modify member\n";
return $param[0];
}
my $string1="aaa";
my $string2="aaa";
modifyString($string1);
$string2 = modifyString($string2);
print "string1 =$string1 will restore to its original value (not call by reference)\n";
print "string2 =$string2 (only if you assign by functoin return value, the string changes\n";
沒有留言:
張貼留言