Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Dear monks,
am writing an simple program, its throwing error
#!/usr/local/bin/perl
$regex = '\d+';
$mod = 'i'
$string = 'my age is 30';
#if($string =~ m/$regex/i) # -- works
if($string =~ m/$regex/$mod) # this line gives error
{
print "Matched";
}
else
{
print "not matched";
}
when i run it
BL05ACLS: ~ 51 > regex.cgi
Scalar found where operator expected at ./regex.cgi line 8, near "m/$regex/$mod"
syntax error at ./regex.cgi line 8, near "m/$regex/$mod"
Execution of ./regex.cgi aborted due to compilation errors.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: configurable regex match
by JavaFan (Canon) on Aug 13, 2009 at 16:42 UTC | |
by perl_fan (Novice) on Aug 13, 2009 at 17:47 UTC | |
|
Re: configurable regex match
by biohisham (Priest) on Aug 13, 2009 at 17:46 UTC |