Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Support for hash comments on a line

by sevensven (Pilgrim)
on Nov 01, 2001 at 23:18 UTC ( #122637=note: print w/replies, xml ) Need Help??


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
Node Status?
node history
Node Type: note [id://122637]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2020-10-23 03:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (234 votes). Check out past polls.

    Notices?