princepawn has asked for the wisdom of the Perl Monks concerning the following question:

There are two possible ways on our system that a file might look that encode the date within the filename. Here are samples of each:
execs.000920103000 000920_092901.nasd
I wrote the following boolean function, which I will pass to
@todays_file = grep { -f $_ && todays_file $_ } @ftp_file_list
in order to get the files I need to ftp for today.

However, I always antsy about my regular expressions (as Jeffrey Freidl said, you can write REs to match what you want, but you also must make sure that they dont match ALL the possible things that can show up that you do not want.)

Replies are listed 'Best First'.
(Ovid) Re: Extracting date encodings from a filename
by Ovid (Cardinal) on Sep 20, 2000 at 20:10 UTC
    If you can give us better specs, we can probably whip something out for you (though, to be fair, date matching is a much harder problem than it appears, if there is a great danger of similar numbers.

    My guess is that you have a two digit year, followed by a two digit month and a two digit day, but I'm not sure about the rest of the numbers or whether or not the letters (such as nasd) will change. If you wish, you can build that date substring by using localtime. This will simplify the regex.

    my ($day, $month, $year) = (split (/\s|:/, localtime))[2,3,6]; $year = substr $year, 2,2; my $date = $year . $month . $day;
    This assumes that you always need files with todays date stamp. You'll need to modify it to fit your particular needs.

    Cheers,
    Ovid

    Join the Perlmonks Setiathome Group or just go the the link and check out our stats.

A reply falls below the community's threshold of quality. You may see it by logging in.