Argel has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Is there a way to clean up this backticks wrapper?
by BrowserUk (Patriarch) on Feb 16, 2010 at 00:05 UTC | |
by Argel (Prior) on Feb 16, 2010 at 00:31 UTC |