Dear Monks -
I'm having a problem with a another problem that I experienced
before. I have three different text files. One is a master file, one is a delete file and another is a add file. I need to remove the contents of the deleted file from the master file and add the contents of the add file to the new master file. I figured this would be fairly trivial given what I learned from my previous problem and yet I can't get this to work.
#!/usr/bin/perl -w
use strict;
my $dir = "/foo/";
my $raw_file = $dir."sample_qw_zips.txt";
my $delete_file = $dir."sample_qw_deletes.txt";
my $add_file = $dir."dsl_capable_add_0615.txt";
my %delete = ();
open (DELETE_FILE, "< $delete_file")
or die "Can't open $delete_file: $!\n";
open (RAW_FILE, "< $raw_file")
or die "Can't open $raw_file: $!\n";
open (OUTPUT, "> output.txt")
or die "Can't open OUTPUT: $!\n";
#populate delete hash
while (my $deleted_zip = <DELETE_FILE>) {
chomp $deleted_zip;
$delete{$deleted_zip} = 1;
}
while (my $raw_zip = <RAW_FILE>) {
chomp $raw_zip;
# strings in a weird place in a weird place
my $zip = substr($raw_zip, 3, 9);
# maybe use an unless statement
if (exists $delete{$zip}) {
# don't do anything
} else {
print OUTPUT $raw_zip, "\n";
}
}
close DELETE_FILE;
close RAW_FILE;
close OUTPUT;
You'd think after all these years I would be more comfrtable with hashes. Nope.
Thanks.