in reply to Using flag files to monitor cluster jobs

Stick the names you are looking for in an array and splice them out as they are found. When the array is empty, all your jobs are done.

Update: See benizi's post below for an important correction to this untested logic.

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

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.

Replies are listed 'Best First'.
Re: Using flag files to monitor cluster jobs
by benizi (Hermit) on Oct 31, 2005 at 17:03 UTC

    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";

      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.