Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Only-in

DZone's Guide to

Only-in

·
Free Resource
see: http://www.perlmonks.org/?node_id=138288


#!/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;
Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}