use strict;
my $word='word2';
my $para='word1 word2 word3';
my $re=qr{$word};
if($para =~ $re) {
print "what follows the match = $'\n";
} else {
print "why wasnt '$word' found in '$para'?????\n";
}
Hope this helps - Tobias
________________________________
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
Greg Aiken
Sent: Thursday, June 05, 2008 5:31 PM
To: [email protected]
Subject: eval { $variable_regex_command }; seems not to work for
me...
i would like to do a pattern match where the thing to be matched
is a $VARIABLE, not a previously known value that could otherwise be
simply 'hard-coded' into the regex (as most regex users do). I need to
do something more dynamic than that...
so i assign the regex program line to a scalar, then eval the
scalar.
on the surface, this should work. (and i can swear that in the
very old days with perl 4.036 on win95, it actually did). but now that
i run activeperl 5.8.8 build 822 on xp this ability seems not to work
for me. of course, this could also be my mis understanding, or my
mistake. perhaps those with more expertise than myself can take a quick
look at my code.
here is simple code demonstrating what i am attempting to do:
$word = 'word2';
$paragraph = 'word1 word2 word3';
$block = "\x24paragraph =~ \x2F$word\x2Fi;";
print "block to eval = $block\n";
eval { $block }; warn $@ if $@;
if ($') {
print "what follows the match = $'\n";
} else {
print "why wasnt '$word' found in '$paragraph'????\n";
}
running it displays clearly that 'word2' is not found within the
string containing 'word1 word2 word3'.
i dont understand why this simple example does not work.
your help would be GREATLY appreciated.
_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs