Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Re: simple (in theory) regexp question

by CukiMnstr (Deacon)
on Apr 14, 2002 at 20:44 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://159003]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2024-04-18 07:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found