in reply to A Problem With Hashes and Keys
You want something like Tie::File. This would allow you to edit the master file in place (unless that's a problem) Also it seems like you only need an array, as there is no association to be made (ie all it seems you are populating is that a hash key hashes to one when it needs to be deleted. You would be better off doing something like this
that's untested but its how i see it working best...Tie::File is a good option.. but if you're wanting to keep the same format.. this should work. This is all assuming that your delete file isn't ginormous.open(DELETE,$file) or die "$!"; my @delete = <DELETE>; chomp for(@delete); close(DELETE); open(MASTER,$file) or die "$!"; open(OUTPUT,$file) or die "$!"; while(<MASTER>) { my $zip = substr($_, 3, 9); if(!deletable(\$zip,\@delete)) { print OUTPUT, $zip; } } close(OUTPUT); close(MATSER); sub deletable { my ($item,$list) = @_; my $rv = 0; foreach(@{$item}) { if($$item eq $_) { $rv = 1; last; } } return $rv; }
|
|---|