On May 7, Craig Moynes/Markham/IBM said:

>mmmm interesting ideas.  I will definitely use the self-documenting
>variable creation method, extra assignments be damned :)
>
>Would it also be wise to use the qr// ?
>
>Such as:
>my $shortDayName   = qr/(Mon|Tue|Wed|Thu|Fri|Sat|Sun)/;
>
>then for example I could do:
>my $abcXYZ          = qr/$shortDayName ABC/;

You don't need to use the ()'s in the regex if you don't plan on capturing
anything, by the way.

Also, qr// is very helpful.  Watch:

  my $shortDayName = "Mon|Tue|Wed|Thu|Fri|Sat|Sun";
  my $abcXYZ = "$shortDayName ABC";

Sadly, $abcXYZ is rendered as

  Mon|Tue|Wed|Thu|Fri|Sat|Sun ABC

which puts the " ABC" as part of matching "Sun".  Not what you'd like.

  my $shortDayName = qr/Mon|Tue|Wed|Thu|Fri|Sat|Sun/;
  my $abcXYZ = qr/$shortDayName ABC/;

Here, $abcXYZ is rendered as

  (?-ismx:(?-ismx:Mon|Tue|Wed|Thu|Fri|Sat|Sun) ABC)

Perhaps it's a bit more noise, but that's how the regexes are
formed.  Note the (?:...)s.

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
Are you a Monk?  http://www.perlmonks.com/     http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc.     http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter.         Brother #734

Reply via email to