sub cmd_wrapper { my $cmd = shift; # CASE: Called in list context if( wantarray() ) { my @out; eval { local $SIG{ALRM} = sub { die "alarm\n" }; alarm 15; # Give the command 15 seconds to return @out = `$cmd`; alarm 0; }; return @out; } # CASE: Called in scalar context else { my $out; eval { local $SIG{ALRM} = sub { die "alarm\n" }; alarm 15; # Give the command 15 seconds to return $out = `$cmd`; alarm 0; }; return $out; } }
Elda Taluta; Sarks Sark; Ark Arks
In reply to Is there a way to clean up this backticks wrapper? by Argel
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |