in reply to Re: print a determinate line number
in thread print a determinate line number

Now I explain better my problem, I have to compare the text lines like this: the first with the second, the second with the third and so on and if the following line is different from the previous i have to print it.

Replies are listed 'Best First'.
Re^3: print a determinate line number
by almut (Canon) on Oct 06, 2009 at 12:42 UTC
    if the following line is different from the previous i have to print it

    For that, you'd have to keep the previous line:

    my $prev; while (<>) { print if defined($prev) and $_ ne $prev; $prev = $_; # update $prev }

    (The defined check would skip the first line, as there isn't really one previous to it...)

Re^3: print a determinate line number
by arun_kom (Monk) on Oct 06, 2009 at 12:59 UTC
    ah i see it now ;) ... something like this then.
    use strict; use warnings; my $previous_line; while(<DATA>){ chomp; if($.==1){ $previous_line = $_; next; } if($_ eq $previous_line){ print "Line $. : $_\n"; } $previous_line = $_; } __DATA__ a b b c c c d
    UPDATE:

    Sorry the code above prints the duplicated lines, which is the opposite of what you wanted. i see that almut already has an elegant solution for you.

      Thanx a lot, i have just added some control but it works.