我想用一个子程序从几个大数组中删除元素.我使用引用来避免副本进入子.
@a=qw(ok now what is hi the matter);
sub zonk {
$array=shift; # this is a reference of an array
foreach $i (0..$#$array) { # I saw some say to avoid last element to get size
#if (@$array[$i] =~ /hi/) { delete @$array[$i]; }
#if ($array->[$i] =~ /hi/) { delete $array->[$i]; }
#if ($array->[$i] =~ /hi/) { delete @$array->[$i]; }
if ($array->[$i] =~ /hi/) { print "FOUND "; }
print $array->[$i],"\n";
}
@$array = grep{$_} @$array; # removes empty elements …Run Code Online (Sandbox Code Playgroud)