Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
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
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 cooling their heels in the Monastery: (16)
As of 2014-09-30 18:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (379 votes), past polls