Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Sorry for obviously not describing my problem clear enough, so here is the updated Question.

I can use perl 5.010 and there is no problem in reading the complete inputfile in memory.

I have text in a file of the following form, where the dots stands for a random amount of other text. After reading the input-file, all the newline characters are removed and my text is in $line.

.....P1p1/6P1/7P/5PK1/8 w - - 4 34"] {Weiß am Zug} * ..... 1n5P/1P4PK/1q6 b - - 2 42"] {Weiß am Zug} * ..... .......5K2/3R4 w - - 1 33"] {Weiß am Zug} * .....

If I have a space, followed by the letter b, followed by another space, as shown here in the third line, I want to substitute only the following 'Weiss' with 'Schwarz' and then continue to go through the text until there is another occurence of the pattern (space, followed by the letter b, followed by another space), when the next substition should follow.

So the core of the problem is: If I find a certain pattern-1 in the text, then go on till I find a certain pattern-2 and substitute this with a pattern-3. Do this again for the whole text. I have tried the following:

my $line = do { local $/; <>; }; $line =~ s/\n/ /g; # if ( $line =~ m/\sb\s/ ) # { # $line =~ s/Weiss/Schwarz/g; # } $line =~ s/(?<=\sb\s)Weiß/Schwarz/g; ... print $line;

but neither of this gives me the desired result, the text didn't change. How to solve this problem?

In reply to Regex with condition by OldChamp

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others avoiding work at the Monastery: (3)
    As of 2019-08-21 09:25 GMT
    Find Nodes?
      Voting Booth?

      No recent polls found