Popcorn Dave has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying to evaluate a user supplied regex and when I test m/ for some reason it's not returning the $& variable.
Test code follows:
#!/usr/bin/perl $user_text="drab"; $regex='m/ab/'; eval "'drab' =~ $regex"; print "User: $user_text, Reg: $regex\n"; print "Match:$&\n"; my $i = 1; my $var='$'.$i; print "Fine\n" if defined(eval"$var"); while (defined(eval"$var")){ print "Got here too...\n"; my $found=eval"$var"; print "Var $var is $found\n"; $var='$'.++$i; }
I've had close to a tin of Penguin mints tonight trying to debug this one. :)
I've learned quite a lot in the process ( fixed the other errors ), but unfortunately not what I needed to fix this problem.
Any ideas and/or help is greatly appreciated.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Problems evaluating a user supplied regex using eval (boo)
by boo_radley (Parson) on Apr 24, 2002 at 06:26 UTC | |
by Popcorn Dave (Abbot) on Apr 24, 2002 at 18:50 UTC |