in reply to Removing duplicate lines from a file

Much better, but you should also learn about perltidy :). You should start all your scripts with:

use warnings; use strict;
this will help you to catch errors like this:
if ($index == scalar(@softed)){
note softed here. Also you can write
unless ($prev eq $line){ push (@filtered,$prev); }
instead of
if ($prev eq $line) { } else { push (@filtered,$prev); }

Replies are listed 'Best First'.
Re^2: Removing duplicate lines from a file
by johngg (Canon) on Jan 19, 2009 at 23:46 UTC
    ... Also you can write
    unless ($prev eq $line){ push (@filtered,$prev); }

    I would go a little further by using a statement modifier and I'd also omit the brackets around the push arguments. That saves typing two pairs of brackets and a pair of braces and, to my eye, looks clearer; others may disagree.

    push @filtered, $prev unless $prev eq $line;

    Cheers,

    JohnGG

Re^2: Removing duplicate lines from a file
by jethro (Monsignor) on Jan 19, 2009 at 22:53 UTC
    or equally simple
    if (not $prev eq $line) {
    or if ($prev neq $line) {