Prints:#!/usr/bin/perl use strict;use warnings; while (my $line=<DATA>) { $line=~s/(?<!\\)#.*//; print $line; } __DATA__ \#Not a comment #Comment \#Not a comment #But this is a comment arbitrary text #Comment arbitrary text \#Not a comment arbitrary text \#Not a comment #But this is a comment arbitrary text #Comment \#This is part of the comment
The '(?<!' construct looks backward to ensure that the escape character is not preceeding the comment character.\#Not a comment \#Not a comment arbitrary text arbitrary text \#Not a comment arbitrary text \#Not a comment arbitrary text
In reply to Re: Stripping Comments
by varian
in thread Stripping Comments
by hangon
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |