in reply to Re: Using flag files to monitor cluster jobs
in thread Using flag files to monitor cluster jobs

When using splice in a loop like that, don't forget to reverse the indices. (Splicing at index N doesn't affect indices 0..N-1, but it does map indices N+1..$#END to N..$#END-1.) And you should specify the length (1, in this case) of the array to be spliced out.

e.g. Using your code, with @dirs = qw/A B C/;, and running "touch A/analysis_completed" from another shell.

$ tree . |-- 503170.pl |-- A |-- B `-- C $ perl -l 503170.pl All done $ tree . |-- 503170.pl |-- A | `-- analysis_completed |-- B `-- C

When A/analysis_completed exists, your code splices the entire @rFiles array. The following would do the right thing:

my @dirs = qw[ ... ]; my @rFiles = map{ "$_/analysis_completed" } @dirs; while (@rFiles and sleep 15) { -e $rFiles[$_] and splice @rFiles, $_, 1 for reverse 0..$#rFiles; } print "All done";

Replies are listed 'Best First'.
Re^2: Using flag files to monitor cluster jobs
by BrowserUk (Patriarch) on Oct 31, 2005 at 17:59 UTC

    Very good point.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.