in reply to File Manipulation - Need Advise!

This is an easy problem to solve (and you can sort multiple ways with the same code) if you will use a hash (I'll note the link shows yet another way to do this kind of operation).

#!/usr/bin/perl use warnings; use strict; use Getopt::Long; use Pod::Usage; =head1 NAME unique.pl -- examines data and keeps the unique ones. =head1 SYNOPSIS unique.pl [options] Options: --help Brief help message --man Full documentation --first Keep the first one found rather than the last. =head1 DESCRIPTION unique.pl -- examines data and keeps the unique ones. Program can keep the first or the last one found. =cut my $help = 0; my $man = 0; my $first = 0; GetOptions( 'help|?' => \$help, man => \$man, first => \$first, ) or pod2usage(2); pod2usage( -exitval => 0, -verbose => 1 ) if $help; pod2usage( -exitval => 0, -verbose => 2, -noperldoc => 1 ) if $man; my %hash = (); while(<DATA>) { chomp; my ( $comp, $id, $status ) = split ( /\s+/, $_, 3 ); next if ( $comp =~ m/COMPUTER/ ); if ( $first ) { next if ( defined( $hash{$comp} ) ); } $hash{$comp} = [ $id, $status ]; } for ( sort keys %hash ) { printf "%s %s %s\n", $_, $hash{$_}->[0], $hash{$_}->[1]; } __DATA__ COMPUTER DISTRIBUTION_ID STATUS 30F-WKS `1781183799.xxxx1' IC--- 30F-WKS `1781183799.xxx11' IC--- ADM34A3F9 `1781183799.41455' IC---
and the results are:

C:\Code>perl unique.pl --help Usage: unique.pl [options] Options: --help Brief help message --man Full documentation --first Keep the first one found rather than the l +ast. C:\Code>perl unique.pl 30F-WKS `1781183799.xxx11' IC--- ADM34A3F9 `1781183799.41455' IC--- C:\Code>perl unique.pl --first 30F-WKS `1781183799.xxxx1' IC--- ADM34A3F9 `1781183799.41455' IC---