Beefy Boxes and Bandwidth Generously Provided by pair Networks DiBona
Welcome to the Monastery
 
PerlMonks  

Re: Support for hash comments on a line

by 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.


in reply to Support for hash comments on a line

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://122637]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.