Dan Muey wrote:
> Howdy list
> 
> I currently have to do this via the command line:
> 
>  my @unique = qx(sort -u file.txt);
> 
> To remove duplicat elines from file.txt.
> 
> What would be the best way to do the same thign with perl
> instead of calling an external program?
> 
> I can always assign each element of the array to a hash I suppose,
> that way there could only be one key that is whatever element.
> 
> I was hoping for a one liner though.

To remove duplicates from an array and preserve order:

   @arr = do { my %seen; grep !$seen{$_}++, @arr };

And see also perldoc -q duplicate

HTH

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to