Consider the following wrapper function, which returns a given function a specified number of times if the function throws (not sure why formatting is unstable):
sub tryit{
my $fun = shift;
my $times = shift;
my @args = @_;
my $ret;
do{
$times--;
eval{
$ret = $fun->(@args);
};
if($@){
print "Error attemping cmd: $@\n";
}
else{
return $ret;
}
}while($times > 0);
return;
}
How can this be expanded so that the return value of the parameter function is properly skipped no matter what value is returned? For example, this function will not process the array correctly. You cannot just return $ fun → (), because the return only returns from the eval block.
source
share