Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Re: simple (in theory) regexp question

by CukiMnstr (Deacon)
on Apr 14, 2002 at 20:44 UTC ( #159003=note: print w/replies, xml ) Need Help??


in reply to Re: simple (in theory) regexp question
in thread simple (in theory) regexp question

% perl -i -pe 's/^--(.*)\n//g' your_file

hm. that would delete every line that starts with two dashes (the original poster wanted to keep those lines).

Update: removed the 'm' modifier bit, since the code was acting on the file, instead of acting on the 'slurped' file.

hope this helps,

Replies are listed 'Best First'.
Re: Re: Re: simple (in theory) regexp question
by Juerd (Abbot) on Apr 14, 2002 at 20:50 UTC

    . also, you want the 'm' modifier for the s/// operator, since the whole file is read into a scalar

    Which is not true with -pe without an alternative line ending. The file is read line-by-line.

    the original poster wanted to keep those lines

    So you're doing the exact opposite. I'm sure that'll help. Sigh. How about:

    perl -i -pe'$_ = "" unless /^--/ or !/\S/'
    which does what the original poster wants (If I understood correctly).

    Update - This was meant to be a reply to the parent of the node I replied to. This node's parent didn't have the code indented in a way I recognised as being a quote, and I didn't view the message in its context when I replied. To everyone who cites: please use <blockquote>. I use <p><blockquote><em> quote </em></blockquote></p><p> answer </p>, and even have that in my signature for ease of use.

    - Yes, I reinvent wheels.
    - Spam: Visit eurotraQ.
    

        which does what the original poster wants (If I understood correctly).

      I think you did. I think I was hasty :)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://159003]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2020-02-21 16:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What numbers are you going to focus on primarily in 2020?










    Results (96 votes). Check out past polls.

    Notices?