Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
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 ( [id://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

Replies are listed 'Best First'.
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 (Patriarch) 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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://205615]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (1)
As of 2024-04-25 01:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found