in reply to Disable Regex
returns illegal[bs]characters[a]example[q] is because the two \s are actually \ as an escape and then as the escaped character. From Quote and Quote like Operators:my $test = 'illegal\\\\characters*example?'; my @illegal = qw(\ * ?); my @legal = qw(bs a q); my $c = 0; foreach my $val (@illegal) { $test =~ s/\Q$val\E/[$legal[$c]]/g; $c++; } print $test."\n";
A single-quoted, literal string. A backslash represents a backslash unless followed by the delimiter or another backslash, in which case the delimiter or backslash is interpolated.
If you are building up your string from component parts, it shouldn't be a concern.my $test = 'illegal\\\\characters*example?'; my @illegal = qw(\ * ?); my @legal = qw(bs a q); my $c = 0; foreach my $val (@illegal) { $test =~ s/\Q$val\E/[$legal[$c]]/g; $c++; } print $test."\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Disable Regex
by AnomalousMonk (Archbishop) on Aug 26, 2009 at 06:20 UTC | |
|
Re^2: Disable Regex
by SavannahLion (Pilgrim) on Aug 26, 2009 at 07:04 UTC | |
by james2vegas (Chaplain) on Aug 26, 2009 at 07:11 UTC | |
by SavannahLion (Pilgrim) on Aug 26, 2009 at 07:26 UTC | |
by ig (Vicar) on Aug 27, 2009 at 09:05 UTC |