in reply to foreach loop mistake with key as regexp
my $html = 'this is the user text: «<!--usertext-->»'; my $userinput = 'Some text :)'; $html =~ s/<!--usertext-->/$userinput/is; print $html, $/; __END__ this is the user text: «Some text :)»
What you describe usually happens when you try it the other way round, ie treat $userinput as a regex. Then you should use quotemeta or m/\Q$userinput\E/ instead.
Also consider using a real template system like HTML::Template or HTML::Template::Compiled, and escaping "evil" characters like <>"& in your user input before you send it back to the browser. Both template engines also offer the default_escape option which you can set to "HTML", then you never worry about such things again.
|
|---|