
philgoodbike
New User
Oct 28, 2010, 8:41 AM
Post #1 of 1
(776 views)
|
The dollar issue in evaluated regexps
|
Can't Post
|
|
This is a problem I want to solve for long, and I've already tried hard to solve it. So I need an expert's help to find out how to deal with the "$" in an evaluated regexp. In evaluated regexps the dollar is seen as a variable sign only, but not as a line end (with m modifier) I want to keep the possibility to use $ for line end. The code describes the issue (under linux) : When $Text_find_str has no dollar, it works with the dollar sign it doesn't ############################## #!/usr/bin/perl -w # This should remove the "ikos analyze_off" line from $text # but the dollar sign is not correctly interpreted my $text = "-- ikos analyze_off\n--pragma synthesis_off\n"; my $Text_typeRegExp = '=~'; my $Text_find_str = '^\s*--\s*ikos\s+analyze_o(ff|n).*$\n'; #my $Text_find_str = '^\s*--\s*ikos\s+analyze_o(ff|n).*\n'; my $Text_repl_str = ''; my $Text_modifier = 'm'; print "1> \$text = \[$text\]\n"; print "2> $Text_typeRegExp\n"; print "3> $Text_find_str\n"; print "4> $Text_repl_str\n"; print "5> $Text_modifier\n"; my $Text_RegExp = "s/$Text_find_str/$Text_repl_str/$Text_modifier"; print "6> \$text $Text_typeRegExp $Text_RegExp\n"; eval "\$text $Text_typeRegExp $Text_RegExp"; print "7> \$text = \[$text\]\n"; ################################ Thx for your help
|