Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re: grep -vf exclude_file to_thin_file in perl

by serf (Chaplain)
on Mar 02, 2009 at 19:21 UTC ( #747529=note: print w/replies, xml ) Need Help??

in reply to grep -vf exclude_file to_thin_file in perl

The way we do things changes over time...

Today if I wrote this it would look more like:

#!/usr/bin/perl # # only-in # find lines which are in the first file, but not in the second. # use warnings; use strict; my ($input_file, $exclude_file) = (shift, shift); die "Usage: $0 INPUT EXCLUDE\n" if ! $exclude_file; my %exclude; open (my $exclude_fh, $exclude_file ) || die "Can't read exclude file '$exclude_file': $!\n"; while (defined(my $exclude = <$exclude_fh>)) { $exclude{$exclude} = 1; } close $exclude_fh; open (my $input_fh, $input_file) || die "Can't read input file '$input_file': $!\n"; while (defined(my $input = <$input_fh>)) { print $input if ! $exclude{$input}; } close $input_fh;
Which would run even faster, and wouldn't do nasty things like:
$ cat file1 $i++; $ only-in file1 file2 Nested quantifiers in regex; marked by <-- HERE in m/^$i++ <-- HERE ; $/ at /home/qmechix/only-in line 27.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://747529]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2018-08-16 12:45 GMT
Find Nodes?
    Voting Booth?
    Asked to put a square peg in a round hole, I would:

    Results (167 votes). Check out past polls.