How can I extract times of different formats from Perl strings?
I receive e-mails at least once a day with price changes. I am attempting to automate the recording of the data. I am fairly new to regex and now more confused tha开发者_JAVA百科n I was 5 hours ago.
Here are some sample lines to parse. Note that the time format is not always the same:
Effective 00:01AM, 10/13/10, PRICES WILL BE AS FOLLOWS UNLESS OTHERWISE NOTED
Effective 00:01 AM, 10/13/10, PRICES WILL BE AS FOLLOWS UNLESS OTHERWISE NOTED
Looking to get time and date into a variable for manipulation later in the script prior to being inserted into a database.
use strict;
use Date::Parse;
for my $line (@lines) {
if ($line =~ /Effective (.+?) PRICES/) {
my ($sec, $min, $hr, $day, $mon, $year) = strptime($1);
$mon += 1;
$year += 2000;
# now you can use $year, $mon, $day, $hr, $min
}
}
/(\d{2}:\d{2}[A-Z]{2}), (\d{2}\/\d{2}\/\d{2})/
Captures 00:01AM
and 10/13/10
from the example line you posted.
精彩评论