in reply to print a determinate line number

sorry if i think too simple, but did you mean you need to print whatever is on the 5th line ... $_ contains it ;)

if( $line_number == 5 ){ print "Line $line_number contains this text:\n", $_, "\n"; }

Replies are listed 'Best First'.
Re^2: print a determinate line number
by Paulux (Acolyte) on Oct 06, 2009 at 12:29 UTC
    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.
      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...)

      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.