Hi Gurus,
Sorry I did not give detailed description of the problem, Here it goes I have a array of file names (file1, file2, file3, file4). Each the duplicates should be removed in the below fashion The lines in file1 should be removed from file2,fiile3,file4,If they exists. The lines in file2 should be removed from file3,file4 if They exists, The lines in file3 should be removed from file4 if they exists. Is there any way apart from forloop Thanks in Advance Siva -----Original Message----- From: John W. Krahn [mailto:[EMAIL PROTECTED] Sent: Thursday, January 03, 2008 4:04 PM To: Perl Beginners Subject: Re: removing duplicate lines across files. Siva Prasad wrote: > > Hi Gurus, Hello, > I want to remove duplicate lines across files. > > Below is the detailed problem, > > > I have file1 file2,file3,file4,file5, > > The lines in file1 are there in file2,file3,file4,file5 I want to remove > all the lines which are there in file1 from file2,file3,file4,file5. > > Can anybody please tell me to solve the above problem? UNTESTED: #!/usr/bin/perl use warnings; use strict; my $file = 'file1'; open my $fh, '<', $file or die "Cannot open '$file' $!"; my %lines; @lines{ <$fh> } = (); close $fh; { local ( $^I, @ARGV ) = qw/ .bak file2 file3 file4 file5 /; while ( <> ) { next if exists $lines{ $_ }; print; } } __END__ John -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in short order. -- Larry Wall -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/