why_bird has asked for the wisdom of the Perl Monks concerning the following question:
Dear Monks,
I'm parsing a configuration file, so before doing the proecssing, I want to remove comments, which I take for granted are in the same style as Perl (i.e. one line comments starting with '#' which can occur after other text, which must be left intact)
Here is my code. It works fine unless it comes across '[]' in a comment in my config file (it works fine if the '[]' is outside a comment), when it throws this:
Unmatched [ in regex; marked by <-- HERE in m/ ...some text... [<-- HERE] ...some more text..
while (chomp(my $temp=<INPUT>)){ print Dumper $temp; if ($temp =~ /#/){ $temp =~ s/#$'//; } if ($temp =~ /^\s*$/){ next; } print "after regex:\n"; print Dumper $temp; print "end\n"; }
I'm a bit new with regexes so chances are I've missed something obvious---any ideas?
thanks!Those are my principles. If you don't like them I have others.
-- Groucho Marx
.......
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Regex error when [] occurs in file..
by moritz (Cardinal) on Mar 03, 2008 at 15:38 UTC | |
by CountZero (Bishop) on Mar 03, 2008 at 17:12 UTC | |
Re: Regex error when [] occurs in file..
by Joost (Canon) on Mar 03, 2008 at 15:42 UTC | |
by why_bird (Pilgrim) on Mar 03, 2008 at 16:03 UTC | |
by Joost (Canon) on Mar 03, 2008 at 16:11 UTC | |
by almut (Canon) on Mar 03, 2008 at 16:31 UTC | |
Re: Regex error when [] occurs in file..
by ysth (Canon) on Mar 03, 2008 at 21:27 UTC |
Back to
Seekers of Perl Wisdom