qr//

created by ariels
(thing) by ariels (3.4 d) (print)   (I like it!) Sun Apr 29 2001 at 15:02:53
In Perl, the operator for creating a regexp. Naturally, it's "pick your own delimiters", like all the other q's. If you pick the single quote ' as your delimiter, the insides obey a "single quote" context ($'s and other variable references not expanded). Otherwise, it's "double quote" context, just like for the m// operator. Watch those @'s (and $'s)!

Storing the result of qr// in a variable lets you compile the regexp just once (when the qr// is evaluated). This is easier than the old way of compiling an anonymous sub that does the matching for you.

You may also use the result of qr// inside another regular expression:

$digits = qr/\d+/;
$sign = qr/[+-]?/;
$float = qr/$sign $digits
            (\. $digits)?
            ([Ee]$sign $digits)?/x;
Y'know, if you log in, you can write something here, or contact authors directly on the site. Create a New User if you don't already have an account.