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

parsing a txt file

by baxy77bax (Chaplain)
on Nov 09, 2010 at 12:26 UTC ( #870286=perlquestion: print w/ replies, xml ) Need Help??
baxy77bax has asked for the wisdom of the Perl Monks concerning the following question:

hi, ppl

i need a little help

so in this txt file i have there are two dictinctive markers marking let say 10th and 31th row. to every line that contains any data between those two markers i have to add a symbol X. is there a simpli way to do it somehow with just using s///

marker1 i was here and now i am going to USA jipi marker2

Comment on parsing a txt file
Download Code
Re: get data from the database -CGI
by moritz (Cardinal) on Nov 09, 2010 at 12:39 UTC
    while (<>) { s/^/X/ if /marker1/.../marker2/; print; }

    Or something along those lines. If you describe your problem better, and what you tried, and where you are having problems, I might give you a better answer.

    P.S. what does the title of your question has to do with the rest of the question?

    Perl 6 - links to (nearly) everything that is Perl 6.
      I have used the standard "flip-flop" .. operator for similar things, but always had to explicitly exclude the start and end points i.e. marker1 and marker2.

      Does the ... remove the need for this? Is this only for more recent Perl versions (still stuck on 5.8)?

        Why don't you just try it?
        Perl 6 - links to (nearly) everything that is Perl 6.
Re: parsing a txt file
by ssandv (Hermit) on Nov 09, 2010 at 17:25 UTC
    The simple way to do it is one that makes sense when you look at the code again in 3 months, not the one that uses the fewest characters or lines of code. I think the only way to do it with just a single s/// involves some ugly lookahead/look behind stuff, and would probably run very slowly.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (13)
As of 2014-09-02 15:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (25 votes), past polls