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

Re: Re: How can I remove 0 from first line and empty space from the start of the following line and join them

by krusty (Hermit)
on Oct 16, 2002 at 02:34 UTC ( #205615=note: print w/ replies, xml ) Need Help??


in reply to Re: How can I remove 0 from first line and empty space from the start of the following line and join them
in thread How can I remove 0 from first line and empty space from the start of the following line and join them

An efficient alternative to:

while (<DATA>) { $_ .= <DATA>; s/^0\s*(.*)\n\s+(.*\n)/$1 $2/s; print; }
is not to even loop at all.
{ local $/ = undef; $_ = <DATA>; s/^0\s*(.*)\n\s+(.*\n)/$1 $2/s; print; }
caveat is that it eats up memory if you have an extremely large file.

Cheers,
Kristina Update: See BrowserUK's post immediately below. /s would allow the "." to match the newline which I don't want to happen here, but /m will treat the single string as multiple lines and /g will let me match more than once before quitting.


Comment on Re: Re: How can I remove 0 from first line and empty space from the start of the following line and join them
Select or Download Code
Re: Re: Re: How can I remove 0 from first line and empty space from the start of the following line and join them
by BrowserUk (Pope) on Oct 16, 2002 at 02:40 UTC

    It would.... if you added /mg options instead of /s to the regex.



    Cor! Like yer ring! ... HALO dammit! ... 'Ave it yer way! Hal-lo, Mister la-de-da. ... Like yer ring!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2014-07-26 00:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (175 votes), past polls