in reply to Regex error when [] occurs in file..
if ($temp =~ /#/){ $temp =~ s/#$'//; }
That's what's causing the problem: $' can contain arbitrary data, but you try to treat it as a regex.
The "good" solution is to use this regex instead: $temp =~ s/#.*$//;
In general you can also quote interpolated variables, then they are treated as text, not as regexes:
my $varaible = '[a-z]'; m/\Q$variable\E/ # matches literal [a-z], not a character class.
If you're not inside a regex, quotemeta does the same job.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regex error when [] occurs in file..
by CountZero (Bishop) on Mar 03, 2008 at 17:12 UTC |