in reply to Re: how to stop command
in thread how to stop command

Hi :) you mean below script?
my $timeout = 5; eval { local $SIG{ALRM} = sub { die "alarm\n" }; alarm $timeout; my @file_list = `ls user/test/`; my $file; my @file_list; foreach $file(@file_list){ print "$file\n"; } alarm 0; }; if ($@) { die unless $@ eq "alarm\n"; # propagate unexpected errors # timed out } else { # didn't }

Replies are listed 'Best First'.
Re^3: how to stop command
by hippo (Archbishop) on Jul 22, 2018 at 10:52 UTC

    Not quite. I mean more like this:

    my $timeout = 5; my @file_list; eval { local $SIG{ALRM} = sub { die "alarm\n" }; alarm $timeout; @file_list = `ls user/test/`; alarm 0; }; if ($@) { die $@ unless $@ eq "alarm\n"; # propagate unexpected errors # timed out print "Have incomplete file list\n"; } else { print "Have complete file list\n"; } foreach my $file (@file_list) { print "$file\n"; }