in reply to Re: Removing Duplicate Lines from a File
in thread Removing Duplicate Lines from a File

But how do I embed that into a perl program?
  • Comment on Re: Re: Removing Duplicate Lines from a File

Replies are listed 'Best First'.
(jeffa) 3Re: Removing Duplicate Lines from a File
by jeffa (Bishop) on Jul 17, 2002 at 15:44 UTC
    If you run DamnDirtyApe's excellent one-liner through Deparse:
    perl -MO=Deparse -ne 'print unless $n{$_}++' my_file.txt
    you will see how:
    LINE: while (defined($_ = <ARGV>)) { print $_ unless $n{$_}++; }
    You can remove the LINE: label and you should add use strict.

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    
Re: Re: Re: Removing Duplicate Lines from a File
by broquaint (Abbot) on Jul 17, 2002 at 15:44 UTC
    my %uniq; $uniq{$_}++ while <DATA>; print for keys %uniq; __DATA__ B1 name;B1 Bmk;B1 host;B1 arch;B1 mem;B1 dvr;B1 arw; SomeName;Blondie;server15;unix;1;1;32 SomeName;Blondie;server15;unix;2;2;43 SomeName;Blondie;server15;unix;3;3;54 SomeName;Blondie;server15;unix;4;4;65: B1 name;B1 Bmk;B1 host;B1 arch;B1 mem;B1 dvr;B1 arw; SomeName;Blondie;server12;unix;1;5;76 SomeName;Blondie;server12;unix;2;6;87 SomeName;Blondie;server12;unix;3;7;89 SomeName;Blondie;server12;unix;4;8;09;

    HTH

    _________
    broquaint