: >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.
I suspect Craig is capturing the pieces. (This is very similar to
something I did last week, & I wanted the pieces.) My preference in
that case is to put the parens in when the pieces are combined, like
this:
my $shortDayName = qr/Mon|Tue|Wed|Thu|Fri|Sat|Sun/;
my $abcXYZ = qr/($shortDayName) ABC/;
Then the longer regex tells you explicitly how many pieces to expect.
As Jeff points out, the qr// form implicitly groups the individual
pieces for you with "non-saving" parens, so you don't need them at all
in the $shortDayName. Also, if you want day names to be case-insensitive
(say), but ABC always has to be upcased, then you can do:
my $shortDayName = qr/Mon|Tue|Wed|Thu|Fri|Sat|Sun/i;
For a mind-blowing example of this technique of building big regexes
from little ones, see Appendix B of Jeffrey Friedl's book "Mastering
Regular Expressions". And for extra credit, parse the regex on pg 316
by hand. ;)
-- tdk