in reply to Two line match

#!/usr/bin/env perl use warnings; use strict; my $prev = 0; while (<DATA>) { if (/-----/) { print unless $prev; $prev = 1; } else { print; $prev = 0; } } __DATA__ aaaaaaaaaaaa ----- ----- bbbbbbbbbbbb ----- ----- ----- ccccccccccccc

Prints:

aaaaaaaaaaaa ----- bbbbbbbbbbbb ----- ccccccccccccc

Replies are listed 'Best First'.
Re^2: Two line match
by jrosenfeld (Initiate) on Mar 10, 2008 at 15:46 UTC
    That works except that it only converts two lines of ----- into one. I wanted it to be able to convert any number of lines of

    -----

    ------

    ------> into 1 line of it. Shouldn't the /g do that? Jeff

      My code converts 2 consecutive lines of 5 dashes into one line of 5 dashes (between the line of "a"'s and the line of "b"'s).

      My code also converts 3 consecutive lines of 5 dashes into one line of 5 dashes (between the line of "b"'s and the line of "c"'s).

      You can add any arbitrary number of lines of 5 dashes, and they will all be converted to one line of 5 dashes.

      I guess I do not understand your question afterall.