|
|
| Welcome to the Monastery | |
| PerlMonks |
Re: Support for hash comments on a lineby sevensven (Pilgrim) |
| on Nov 01, 2001 at 18:18 UTC ( [id://122637]=note: print w/replies, xml ) | Need Help?? |
This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.
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
|
|
||||||||||||||||||||||||