foreach (@files) { /(prefix)(_)(\d+)(_)(\d+)(_)(\w+)(_)(\w+)(_)(\w+)(\.)(\w+)/; $filename = "$1$2$3$4$5$6$7$8$9$10$11$12$13"; print "name of file: $filename \n"; print "\n";<c>
That's ugly. You've been previously shown a much more compact and clear way to do this. Okay, we'll move on to the current question, but your failure to incorporate previous lessons does not bode well for future enlightenment.
use strict; use warnings; my $counter = 0; # get last step completed, if any my $file = glob("S*.txt"); if (defined $file) { ($counter) = $file =~ m/S(\d+)\.txt/; } printf "Ready to start step %d\n",++$counter; if ($counter == 1) { print "Just getting started.\n" } elsif ($counter > 1 && $counter <= 4) { print "All kinds of interesting intermediate processing goes on here +.\n" } elsif ($counter == 5) { print "Finishing up.\n" } print "Completed step $counter.\n"; stepfile($counter); # forget previous step, if any, now that this one is done unlink $file if (defined $file); sub stepfile { my $step = shift; my $filename = sprintf "S%06d.txt",$step; open my $tfh,'>',$filename; }
This differs some from the approach in your code, which creates all 5 step files first. This code looks for a single file containing the last completed step number to determine what step do next, does it, and when finished creates a file showing how far it got, and removes the last file.
In reply to Re: check for latest file, remove and touch file?
by GotToBTru
in thread check for latest file, remove and touch file?
by fasoli
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |