Funny, I've begun this question and killed it to try some things on my own about 5 times this morning! Anyway, my problem is that I want to "do something" to files created within a certain range of dates, inclusively. And I'm stuck. Here's what I've got so far; be gentle as I'm new at this programming stuff.
#!/usr/local/bin/perl -w
use strict;
my $test_arg = $ARGV[0];
my @string = split('-',$test_arg);
my $beg_date = $string[0];
my $end_date =$string[1];
my $date = $beg_date;
my @list;
if ($string[0] ge $string[1]) {
die "Invalid date range\n";
}
elsif ($test_arg =~ /\d{8}-\d{8}/){
$test_arg = "1";
}
else {
$test_arg = "0";
}
die "Usage: $0 <yyyymmdd-yyyymmdd>\n" unless $test_arg == "1";
while ($date <= $end_date){
push (@list, $date);
}
continue {
$date++;
}
The array
@list is getting populated by the date string that I will use for my file search. My problem is accounting for the fact that months have either 28, 29, 30, or 31 days, depending upon year and month.
As writtren, the given date range 20010101-20010201 will return 100 days!
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.