Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

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.
:o)


Comment on Re: grep -vf exclude_file to_thin_file in perl
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2014-10-26 05:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (151 votes), past polls