in reply to Re: Timing out ``?
in thread Timing out ``?

To give a concrete example of that:

use warnings; my @list = (); eval { local $SIG{ALRM} = sub { die "SSH timed out" }; alarm 5; #If after 5 seconds nothing happens, then call SIGALRM @list = `ssh machine "ls path"`; alarm 0; #Reset }; if( $@ ) { warn "I could not do that: $@"; } else { do_something_with( @list ); }

Update: After being corrected, I have changed the code to make it work

~Thomas~
confess( "I offer no guarantees on my code." );

Replies are listed 'Best First'.
Re^3: Timing out ``?
by kennethk (Abbot) on Jun 06, 2012 at 23:57 UTC
    No. As the docs say,
    If you want to use alarm to time out a system call you need to use an eval/die pair.
    Your code will emit a warning, but will continue to hang until the backticks return.

    Update: Parent's code has been corrected.

    #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

Re^3: Timing out ``?
by slgilley (Initiate) on Jun 07, 2012 at 12:49 UTC

    This is exactly what I was looking for. I've done similar things in C, just wasn't sure how to handle it in Perl.

    Thanks,

    Sean.