There are safer way to use eval, or even avoid it all together
Re^3: My Favourite Regex Tools (Was: Parsing a Variable Format String)
It can be as simple as
use String::Interpolate::RE qw( strinterp ); print Substitution( "input string", "pattern", "replacement", "flags" ); sub Substitution { my( $in, $re, $rep, $flags ) = @_; my $global = $flags =~ m{g}i; my $qrFlags = join '', $flags =~ m{[msixpodualn]}i; $qrFlags = "(?$qrFlags)"; $re = qr{$qrFlags$re}; if( $global ){ $in =~ s{$re}{ Replace($rep, \%+,{1=>$1,2=>$2,3=>$3}); }gex; } else { $in =~ s{$re}{ my $vars = { %+, 1=>$1, 2=>$2, 3=>$3, }; strinterp( $rep, $vars ); }ex; } } sub Replace { my( $rep, $named, $numed ) = @_; my $vars = { %$named, %$numed, 'bananas','bananas' ); return strinterp( $rep, $vars ); }
In reply to Re^2: Passing a regex from a CGI HTML form (user supplied regex substitution without eval)
by Anonymous Monk
in thread Passing a regex from a CGI HTML form
by Linicks
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |