P
Patrick Drouin
Hello guys,
I've browsed the web, looked at the camel book and asked around but I
haven't been able to solve what seems to be a simple problem. I want to
load regex on the fly from an external file, that's not a big thing.
The problem I am running into is that these regex used patterns I have
described somewhere else in my program and stored into scalars. Here's
the thing :
Defined in my program (to simplify regex writing by the users):
$nom = '[^\/]+\/(?roper|Common)_Noun\/[^ ]+';
$adj = '[^\/]+\/Adjective\/[^ ]+';
.....
I now have these rules outside:
\s$nom
\s$nom (?:$adj)+
I use them this way :
if(@matches = $line =~ /$regex/g) {save_list(@matches);print "Yup!\n";}
else {print "Nope!\n";}
I'm not getting any "Yup!" back.... It seems that the internal $nom
scalar is not expanded to its definition in the pattern. Is there anyway
to force Perl to do this in a regex?
I've tried defining the first rule as this in the external file and it
works just fine :
\s[^\/]+\/(?roper|Common)_Noun\/[^ ]+
Any help will be appreciated.
Patrick
I've browsed the web, looked at the camel book and asked around but I
haven't been able to solve what seems to be a simple problem. I want to
load regex on the fly from an external file, that's not a big thing.
The problem I am running into is that these regex used patterns I have
described somewhere else in my program and stored into scalars. Here's
the thing :
Defined in my program (to simplify regex writing by the users):
$nom = '[^\/]+\/(?roper|Common)_Noun\/[^ ]+';
$adj = '[^\/]+\/Adjective\/[^ ]+';
.....
I now have these rules outside:
\s$nom
\s$nom (?:$adj)+
I use them this way :
if(@matches = $line =~ /$regex/g) {save_list(@matches);print "Yup!\n";}
else {print "Nope!\n";}
I'm not getting any "Yup!" back.... It seems that the internal $nom
scalar is not expanded to its definition in the pattern. Is there anyway
to force Perl to do this in a regex?
I've tried defining the first rule as this in the external file and it
works just fine :
\s[^\/]+\/(?roper|Common)_Noun\/[^ ]+
Any help will be appreciated.
Patrick