tags:

views:

78

answers:

2

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 than 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.

+1  A: 
/(\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.

chigley
I think I might allow single digits in the month and day portions, and up to 4 digits in the year portion.
brian d foy
@brian - valid point, but based on the string in the OP there'll always be padded zeros on the values.
chigley
I don't see anything about padding anywhere in the question or comments. Even if that were true, when dealing with dirty data you know it's not going to be true. As soon as you could a limiting case, someone else breaks it somehow. :)
brian d foy
Thanks for the help.
+4  A: 
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
    }
}
eumiro
Please post code snippets that `use strict`.
CanSpice
He meant snippets that _work_ with `use strict`. Your code didn't even work without strict. I fixed it for you.
cjm
Thanks, guys! Hopefully this will help OP.
eumiro
Thanks, It did. Now I have something to work with.