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

Answer: How do I strip lines prefixed by a

( #38411=categorized answer: print w/ replies, xml ) Need Help??

Q&A > regular expressions > How do I strip lines prefixed by a "#" contributed by Fastolfe

Generally when I'm reading files that have the potential for comments or blank lines, a simple regular expression or two does the trick:
while (<DATA>) { s/\s#.*//; next unless /\S/; do_something($_); } __DATA__ # This is my file # with a few lines of comments data=here # another comment more=data # more comments and=more # end of file

Comment on Answer: How do I strip lines prefixed by a
Download Code
Replies are listed 'Oldest First'.
RE: Answer: How do I strip lines prefixed by a
by Fastolfe (Vicar) on Oct 25, 2000 at 20:20 UTC
    That first regexp should have read: s/\s*#.*//;
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (9)
As of 2015-07-07 16:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (91 votes), past polls