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

Re: read multi lines of a file in perl

by markov (Scribe)
on Nov 05, 2008 at 13:55 UTC ( #721652=note: print w/ replies, xml ) Need Help??


in reply to read multi lines of a file in perl

The logic of your code is wrong: your print will only happen when the line contains /process/. Try:

local $_; while(<WORDLIST>) { last if /process/; } while(<WORDLIST>) { print; last if /end process/; }
(many more compact notations for the same exist)


Comment on Re: read multi lines of a file in perl
Download Code
Re^2: read multi lines of a file in perl
by sharan (Acolyte) on Nov 05, 2008 at 14:31 UTC
    Hi Markov, Thanks for ur reply.. But i still have a small problem.. as this is able to check for only one loop and not repeated loop.. eg
    process lkhls ksjhfk end process process kfhls kfh end process
    i want output as
    ksjhfk kfh
    Thanks....
      Do this if what only what you require is the bit between:
      print grep { !/process/ } <>;
      perl <script>.pl <input>.txt

      prints
      ksjhfk kfh

      You could also put this in an array
      my @process = grep { !/process/ } <>;
      However this would just be each element for each line. If you wanted them grouped you need something more complex using assertions ( if you do it the inefficent way like i have )
      John,

      UPDATE: This would group them
      { local undef $/; print split /process \s \w+ (.+?) end \s process/xms, <>; }

      P.S. Don't actually use these methods of doing it, There just other ways to do it.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (9)
As of 2015-07-05 08:56 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 (61 votes), past polls