
BillKSmith
Veteran
Oct 24, 2012, 4:10 AM
Post #2 of 4
(533 views)
|
|
Re: [pedrete] Using Regular expresions stored in a scalar
[In reply to]
|
Can't Post
|
|
use warnings; use strict; my $i=qr/hello/; if ("helloeverybody" =~ $i) { print " OK "; } Strict and warnings are not required, but I strongly recommend that you develop the habit of always using them. The my (refer: perdoc -f my) is required by strict. The qr (refer to the section "quote and quotelike operators" in perdoc perlop) tells perl that the string is a regular expression and usually compiles it. Regular expressions can be stored as strings, but then you need the slashes where they are used, not in the definition. Good Luck, Bill
|