http://www.perlmonks.org?node_id=870286

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

Replies are listed 'Best First'.
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.