in reply to Deleting undefined entries from DB_FILE hash
tie (my %hash, 'DB_File', $file, O_RDWR, 0600) || next; foreach my $key ( keys %hash ) { if (!defined $hash{$key}) {
The undef value is an internal perl meta-value. When you store data on an external device (like a tied hash) the undef value is converted to a string, so trying to use defined on this value makes no sense.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Deleting undefined entries from DB_FILE hash
by gossamer (Sexton) on Jul 23, 2012 at 19:07 UTC | |
Hi, Thanks everyone for your offer to help. I've posted below a complete program that runs on my system. Where it encounters an error and quits, it displays the following, with a few of the preceding lines:
It's reading from 255 hashes for each host, which you aren't going to have, so it probably won't execute for you. As I mentioned previously, the delete() isn't actually deleting for some reason. If I run the program again, it dies at the same spot, indicating to me that the record with the undef'd value or key still remained. Any ideas greatly appreciated.
Version with line numbers:
| [reply] [d/l] [select] |
by 2teez (Vicar) on Jul 24, 2012 at 00:45 UTC | |
Instead of this: Try this and see what you get:
| [reply] [d/l] [select] |
by gossamer (Sexton) on Jul 24, 2012 at 02:34 UTC | |
I actually just a few minutes ago removed the LIMIT from the split, and it made no difference alone. I also added the following line directly before the split line:
For values where $hash{$key} isn't defined, it still outputs this:
In other words, the key (the spam-de... filename) is defined, but the rest of the values of the record are not. The rest of the values include the email's subject, so switching \t for \s+ won't work, because email subjects have spaces in them. If I run this program again, it prints the same 'uninitialized value' line at the same spot. Why doesn't it delete() the record? Eventually the hash is "untied", so it's properly closed. That's the issue that really has me perplexed now. Thanks,Alex | [reply] [d/l] [select] |