Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re: Filtering lines from one file from another

by pavunkumar (Scribe)
on Feb 03, 2011 at 05:37 UTC ( #885894=note: print w/ replies, xml ) Need Help??

in reply to Filtering lines from one file from another

Hi, You can try this,
# open file1, fil2 ; open F1 , "$file1" or die "Cant open : $! \n" ; open F2 , "$file2" or die "Cant open : $! \n" ; # Create the hash key with each line of the file2 while (<F2> ) { chomp; $file{$_}=''; } # Print the line , if key does not exist in the hash ; while (<F1> ) { chomp ; print $_ , "\n" unless(exists ( $file{$_} ) ) ; }

Comment on Re: Filtering lines from one file from another
Download Code
Re^2: Filtering lines from one file from another
by Limbic~Region (Chancellor) on Feb 03, 2011 at 16:21 UTC
    Setting aside that you are using bare word filehandles, this is a fine solution assuming one of the files can fit into memory as a perl hash. It may be able to be improved by determining which of the two files is smaller and loading that one into memory (assuming which file should be considered the filter isn't important to antonn). Unfortunately, this solution fails if you need to support arbitrarily large files. I know the description of the problem says one of the files is being read into memory, I am just thinking about the general problem.

    Cheers - L~R

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://885894]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (9)
As of 2014-08-21 20:40 GMT
Find Nodes?
    Voting Booth?

    The best computer themed movie is:

    Results (143 votes), past polls