Perl qr Function
Description
This function quotes its STRING as a regular expression. STRING is interpolated the same way as PATTERN in m/PATTERN/
Syntax
Following is the simple syntax for this function −
qr EXPR
Return Value
This function returns a Perl value which may be used instead of the corresponding /STRING/ expression.
Example
Following is the example code showing its basic usage −
$rex = qr/my.STRING/is; s/$rex/foo/; is is equivalent to s/my.STRING/foo/is;
When above code is executed, it produces the following result −
$re = qr/$pattern/;
$string =~ /foo${re}bar/; # can be interpolated in other patterns
$string =~ $re; # or used standalone
$string =~ /$re/; # or this way
perl_function_references.htm
Advertisements