Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Support for hash comments on a line

by sevensven (Pilgrim)
on Nov 01, 2001 at 23:18 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://122637]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (1)
As of 2024-04-24 14:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found