On Wed, Nov 21, 2001 at 02:25:35PM +0100, Louis Pouzin wrote:
> Hi,
>
> I can't figure out what's wrong in the following. Any hint ?
>
> Thanks
>
> Here is a script:
>
> #!perl -w
> my $days = "Mon|Tue|Wed|Thu|Fri|Sat|Sun";
> while (<DATA>) {$lin = $_;
> /^Date:\s+$days,\s+(\d\d?)/o && do {
> print $lin;
> print "dat1: $& \n";
> print "dat2: $1 \n";
> print "-------\n";
> }
> }
> 1;
Expanding out your regex:
/^Date:\s+Mon|Tue|Wed|Thu|Fri|Sat|Sun,\s+(\d\d?)/
Conjunction in a regex has higher precedence than alternation, so your
regex is parsed as:
/(?:^Date:\s+Mon)|(?:Tue)|(?:Wed)|(?:Thu)|(?:Fri)|(?:Sat)|(?:Sun,\s+(\d\d?))/
You need to put parens around the matching of the days.
Ronald