SPUG: RE question

Menton, Stephen stephen.menton at cingular.com
Wed Nov 16 17:15:48 PST 2005

ParseDate from CPAN module Date::Manip might save you time... If you
can't CPAN it then I'd recommend something long but clear for your own
supportability's sake to match alll the patterns you wish to support.

In other news, your example say "for $thing" but your match checks
"$line". I'm also noticing a lack of "my", heh. Strict and -w are your
friends! ;-)


-----Original Message-----
From: spug-list-bounces at pm.org [mailto:spug-list-bounces at pm.org] On
Behalf Of Duane Blanchard
Sent: Wednesday, November 16, 2005 17:06
To: spug-list at pm.org
Subject: SPUG: RE question

Hello All,

I want to match any one of three formats for dates in a file. I think I
understand the long way to do this, but know there must be a better, or
at least more clever, way to do it. I'm trying the following with no
success. I know it won't work the way I'm trying, but it gives you an
idea of what I am thinking of. What do you guys think? Some dates have
extraneous spaces and some have commas where wouldn't expect them or
don't where I would.



$RE_year = "(19|20)\d\d";
$RE_month =
$RE_day = "[0-3]?\d";

@array = ("1993 Mar  3", "1993  Mar 15", "Mar 15, 1993", "15 Mar 2001",
"2001, 15 Mar");

foreach $thing (@array)
	# in the first disjunction, find any one of the defined REs, in
the second, find any but the first one you found, etc.
	if ($line =~
	{print "You got a date: too bad it isn't with a girl.";}
Duane Blanchard

There are 10 kinds of people in the world;
those who know binary and those who don't.
Seattle Perl Users Group Mailing List  
     POST TO: spug-list at pm.org
SUBSCRIPTION: http://mail.pm.org/mailman/listinfo/spug-list
    MEETINGS: 3rd Tuesdays, Location: Amazon.com Pac-Med
    WEB PAGE: http://seattleperl.org/

More information about the spug-list mailing list