bivouac has asked for the wisdom of the Perl Monks concerning the following question:
You'd think after all these years I would be more comfrtable with hashes. Nope. Thanks.#!/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;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: A Problem With Hashes and Keys
by Grygonos (Chaplain) on Jul 19, 2004 at 14:24 UTC | |
Re: A Problem With Hashes and Keys
by eXile (Priest) on Jul 19, 2004 at 14:11 UTC | |
by bivouac (Beadle) on Jul 19, 2004 at 14:54 UTC | |
by ccn (Vicar) on Jul 19, 2004 at 15:01 UTC | |
Re: A Problem With Hashes and Keys
by meredith (Friar) on Jul 19, 2004 at 14:16 UTC |