in reply to my code works just fine, but how :D

All the lines will end in a new line. But you're seeding @comp with a string that doesn't have a newline. So, on the first run, the only way you get a match if your file contains 4 characters: s, e, e and d, and no newline.

Replies are listed 'Best First'.
Re^2: my code works just fine, but how :D
by ikegami (Patriarch) on Apr 25, 2012 at 17:00 UTC
    Not true. A first line of "|\n" would also match, for example. Fix:
    my @comp = "seed\n"; # Fix 1 while ($line = <>) { push(@comp, $line); print $line if $comp[0] =~ /^\Q$comp[1]\E\z/; # Fix 2 shift(@comp); }

    But why not just use eq?

    my @comp = "seed\n"; while ($line = <>) { push(@comp, $line); print $line if $comp[0] eq $comp[1]; shift(@comp); }

    Simpler still:

    my $last = ""; while (<>) { print if $_ eq $last; $last = $_; }