in reply to Re: Re: Removing duplicates
in thread Removing duplicates

From the Perl debugger session I just ran:

[alex@rand alex]$ perl -de 1 Loading DB routines from perl5db.pl version 1.19 Editor support available. Enter h or `h h' for help, or `man perldebug' for more help. main::(-e:1): 1 DB<1> @file1=qw/dave bob rich jim/; DB<2> @file2=qw/dave rich/; DB<3> foreach(@file1){$list{$_}=1;} DB<4> foreach(@file2){delete $list{$_};} DB<5> print "Remaining elements " . join("; ",keys %list) . "\n"; Remaining elements jim; bob DB<6>
You can fiddle with the 'list' hash as you read the file, so there's no need to use an array as the middle man.

Alex / talexb / Toronto

Life is short: get busy!

PS: When posting code, put it in between 'code' tags. That way it doesn't wrap like normal text.

Replies are listed 'Best First'.
Re: Re: Re: Re: Removing duplicates
by RCP (Acolyte) on Mar 06, 2004 at 18:11 UTC
    Thanks for yout inputs. The below code is how I got the output I wanted.
    #!perl open FILE1, "<file1"; @linesFile1 = <FILE1>; close FILE1; open FILE2, "<file2"; @linesFile2 = <FILE2>; close FILE2; open(MYOUTFILE, ">file3"); open(MYOUTFILE, ">>file3"); foreach $line(@linesFile1) { if(! grep{$_ eq $line} @linesFile2 ){ print MYOUTFILE "$line"; } } print "\n"; close(MYOUTFILE);
    Thanks again.. RCP