This type of string "20111031" is great as long as it has leading zeroes for the months and years as that can be used in a simple string comparison against the current date string.
So how to get the current date string?
Extract the date string from the filename using a regex, then use a simple string comparison and then move the file it if is less than today's date. Here's how to extract the date string..#!/usr/bin/perl -w use strict; my ($year,$month,$day) = (gmtime(time))[5,4,3]; $year +=1900; $month +=1; my $date = sprintf("%4d%02d%02d", $year,$month,$day); print "date = $date\n"; #date = 20111031
I suppose from the formulation of the problem that you are thinking in terms of Windows wildcards and not UNIX regular expressions. Experiment with the above code and I think it will work for you. Report back if you have problems.#!/usr/bin/perl -w use strict; while (<DATA>) { #one of many, many ways to get the 8 digit date my ($date) = /(\d{8}).*.log$/; print "$date\n"; } =prints 20111031 // Oct 31, 2011 20110101 // Jan 01, 2011 =cut __DATA__ AAAA*20111031*.log AAAA*sfdaf*20110101*.log
In reply to Re: Help in using backtick operator
by Marshall
in thread Help in using backtick operator
by manutd
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |