in reply to Examine two files to delete duplicates

Welcome to the Monastery, Coop197823!

Always use strict; and use warnings;, and you should also include a sampling of your input for testing (put that in <code></code> tags like you've done with your code), along with a snip of your expected output. Does the following do what you expect?

#!/usr/bin/perl use warnings; use strict; if ($ARGV[0] && ! $ARGV[1]){ die "Usage: ./script.pl file1.txt file2.txt\n"; } my $file1 = $ARGV[0] || 'in.txt'; my $file2 = $ARGV[1] || 'in2.txt'; my %names; # file 1 open my $fh1, '<', $file1 or die "can't open file $file1: $!"; while (<$fh1>) { next if /^\s*$/; $names{(split)[0]} = 1; } close $fh1 or die $!; # file 2 open my $fh2, '<', $file2 or die "can't open file $file2: $!"; while (<$fh2>) { print if /^(\S+)/ && not $names{$1}; } close $fh2 or die $!;

You can call it like ./script.pl file1.txt file2.txt. If you leave off the arguments, it'll use the defaults provided. If you have one argument but not both, the script will fail.

-stevieb

edit: added check for blank and whitespace-only lines, added @ARGV.