pDale wrote: > On 7/15/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: >> hi pDale -- >> >> In a message dated 7/15/2006 12:35:22 A.M. Eastern Standard Time, >> [EMAIL PROTECTED] writes: >> >>> I'm having a hard time "asking the question" to Google... >>> >>> I want to read regular expressions from a config file to use in >>> substitions, but I can't get the regexp to work for memorized >>> groupings. >> try using eval(), e.g.: >> >> C:[EMAIL PROTECTED]>perl -we "use strict; >> my $p1 = '^([^0-9]*)([0-9].*)$'; my $p2 = '$2 $1'; my $str = 'abc123xyz'; >> eval qq(\$str =~ s/$p1/$p2/); print $str" >> 123xyz abc > > Yes, eval does the trick. > My thanks to Bill and $Bill. > Maybe I *will* be able to get to sleep tonight!
But you can do it without using eval: use strict; use warnings; my $p1 = '^([^0-9]*)([0-9].*)$'; my $p2 = '"'.'$2 $1'.'"'; #Note wrapping it with double quotes my $str = 'abc123xyz'; $str =~ s/$p1/$p2/ee; #Note double e print $str, "\n"; -- John W. Kennedy "The blind rulers of Logres Nourished the land on a fallacy of rational virtue." -- Charles Williams. "Taliessin through Logres: Prelude" _______________________________________________ ActivePerl mailing list [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
