farzanj
asked on
Perl regex substitution
Quick question:
What am I doing wrong? The script doesn't print anything.
Sample data:
There may be more than one dates.
I tried (?e) (?-e) but that did not work either.
What am I doing wrong? The script doesn't print anything.
#!/usr/bin/perl
use warnings;
use strict;
my %mon = ('Jan' => '01', 'Feb' => '02', 'Mar' => '03', 'Apr' => '04', 'May' => '05', 'Jun' => '06',
'Jul' => '07', 'Aug' => '08', 'Sep' => '09', 'Oct' => '10', 'Nov' => '11', 'Dec' => '12');
sub MmmDd
{
my $mmmddyyyy = shift;
my ($mmm, $dd, $yyyy) = split(/\s+/, $mmmddyyyy);
my $string = "$yyyy-$mon{$mmm}-" . sprintf("%02d", $dd);
return "$string";
}
while(<>)
{
s/([A-Z][a-z][a-z])\s+(\d{1,2})\s+(\d{4})/MmmDd("$1 $2 $3")/eg;
}
Sample data:
81 223456789 Jan 2 1999 02:30 am 1222222232224222 123232345
84 111334411 Jan 7 1999 7777 7777 7777 123232345
85 111334444 Jan 2 1999 7777 7777 7777 7777 123232345
86 777777779 Jan 2 1999 7777 7777 6663 111223333
87 111333333 Jan 2 1999 00001111222233334444 111223333
89 111222222 Jan 2 1999 1234333331114123 923457789
90 111444444 Jan 2 1999 111112111121111 923457789
91 111223333 Jan 2 1999 1111222233334444 923457789
92 777777778 Jan 2 1999 777766661234X 222222221
93 111334444 Jan 05 1999 02:30 pm X7777 7777 222222221
94 777777778 Jan 2 1999 777766661234X 222222221
95 923456789 Jan 3 1999 3131 7777 7777 7777 443232366
99 776677778 Jan 2 1999 1222222232224222 923457789
There may be more than one dates.
I tried (?e) (?-e) but that did not work either.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER