Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: How to delete contents between two strings.

by toolic (Bishop)
on Sep 16, 2008 at 16:40 UTC ( #711742=note: print w/ replies, xml ) Need Help??


in reply to How to delete conetents between two strings.

Use the Range Operators:

use strict; use warnings; while (<DATA>) { print unless (/\*\*Temp/ .. /\*\*End/); } __DATA__ **Temp** fdvfd fgd dfgd dfgd **End Temp ** this is test dffdgd this is test dffdgd

prints:

this is test dffdgd this is test dffdgd

Update: Please correct the typo in your title: s/conetents/contents/ Nevermind, Anonymous Monk


Comment on Re: How to delete contents between two strings.
Select or Download Code
Replies are listed 'Best First'.
Re^2: How to delete contents between two strings.
by mscharrer (Hermit) on Sep 17, 2008 at 14:14 UTC
    Uuii, the Range Operator in scalar/boolean mode. I just learned this year about it. Very nice solution, toolic.

    In case the Anonymous Monk, or someone else with a similar homework ;-), needs the ** lines included, the feature that '..' in scalar mode returns an increment for every true evaluation and adds 'E0' on the last, can be used:

    #!/usr/bin/perl use strict; use warnings; while (<DATA>) { my $i = (/\*\*Temp/ .. /\*\*End/); print unless ($i && $i > 1 && substr($i, -2) ne 'E0'); } __DATA__ first second **Temp** fdvfd fgd dfgd dfgd **End Temp ** this is test dffdgd this is test dffdgd

    prints:

    first second **Temp** **End Temp ** this is test dffdgd this is test dffdgd

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2015-07-30 04:51 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 (270 votes), past polls