Keep It Simple, Stupid | |
PerlMonks |
Re: Support for hash comments on a lineby sevensven (Pilgrim) |
on Nov 01, 2001 at 23:18 UTC ( [id://122637]=note: print w/replies, xml ) | Need Help?? |
Your second code was close, but you've forgoten that a regular expression like .* is a greedy expression, it will match everything it can, and indeed a .* can match everything :-) In your seconde example ( $line =~ s/(.*)\#.*/$1/g;) you should change (.*) to (.*?) and it will work as you wanted. Adding the ? makes the previous .* match the smallest possible pattern and leave the rest of the input to the rest of the regexp. This is explained in greater detail in perlre Perl Regular Expressions. HTH, going back to building perl with thread support.
In Section
Seekers of Perl Wisdom
|
|