I have tried out your recommendation and it works perfectly. The only thing I edited was the "my $filename = sprintf "S%05d.gro",$mdstep;" at the end, so that the step filename is always made up from 6 characters in total, including the S in the beginning.

I have a few questions though, the biggest of which comes from the fact that I started this thread with a panicky confusing message. My total steps aren't 5, in fact we don't know how many we will be needing to do, so it can be any number. So the numbers you have used, 4 and 5, are great for me to check the example but I have to now ask if you can explain how to write this bit having in mind that we don't know how many steps we'll do.

In other scripts I've written, I had done something like this when I needed to use a counter:

my $start; my $total; for ($start=0; $start<=$total; $start++) { #do stuff in the loop }

Does this make sense if $total is undefined? Of course if $total is undefined and the total number of steps is unknown, this bit...

elsif ($counter == 5) { print "Finishing up.\n" }

...is redundant, right?

Again thank you very much for your help, it's greatly appreciated :)


In reply to Re^2: check for latest file, remove and touch file? by fasoli
in thread check for latest file, remove and touch file? by fasoli

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.