cosmicperl has asked for the wisdom of the Perl Monks concerning the following question:
Easy I thought... Worked great at first, but suddenly I started getting errors such as:-foreach my $key (%HASH) { $html =~ s/<!--$key-->/$HASH{$key}/gis; }#foreach print $html;
Should be:-foreach my $key (%HASH) {
None of the keys had any brackets in, but the values did. Without specifying 'keys' I was getting both keys and values in $key. Rookie mistake, but after 9yrs still bit me on the ass.foreach my $key (keys %HASH) {
my $userinput = 'Some text'; $html =~ s/<!--usertext-->/$userinput/is;
Results in the error "Unmatched ) in regex; marked by <-- HERE in...". I don't quite understand why this is happening as I only thought brackets did something in the first part of the regexp.my $userinput = 'Some text :)'; $html =~ s/<!--usertext-->/$userinput/is;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Regexp swapping with unmatched brackets
by moritz (Cardinal) on Sep 23, 2008 at 14:50 UTC | |
|
Re: Regexp swapping with unmatched brackets
by wol (Hermit) on Sep 23, 2008 at 15:05 UTC | |
|
Re: Regexp swapping with unmatched brackets
by ysth (Canon) on Sep 23, 2008 at 15:41 UTC | |
|
Re: foreach loop mistake with key as regexp
by Anonymous Monk on Sep 24, 2008 at 06:36 UTC |