Dear Monks, I have a directory with several hundred sets of files (an input, data and output file). The files all begin with a given prefix and have a 4 digit sequential number. i.e.
Kick0000.inp Kick0000.data Kick0000.log
are the input, data and output files respectively. I wish to delete the data files of jobs that did not terminate normally (i.e. jobs where the output does not end in "Normal termination"). The following script, using backticks works, but I'm not sure I've done it in the best way. Mainly, I'm concerned about using backticks twice each iteration. I'd appreciate any advice on whether the backticks really are a problem, and if so, how I could better write this script. Thanks in advance, Madd
#!/usr/bin/perl -s $prefix="Kick"; $Restart="Restart.data"; open (RESTART,"$Restart") or die "Unable to open $Restart for reading\ +n"; $AlreadyDone = <RESTART>; $jobs_run= sprintf '%04d',($AlreadyDone); for (my $j=0;$j<=$jobs_run;$j++) { $job_no=sprintf '%04d',($j); $job_title="$prefix$job_no"; $job_end=`tail -n 1 $job_title.log`; if($job_end !~ /Normal/) { `rm $job_title.data`; } }

In reply to Efficient deletion of files / shell interaction by madd

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.