Learning Perl here, so bear with me... Have a hash that i need to delete the entry out of and am having problems doing that. Basically, I need to delete all entries from the hash that have values over 5,000,000. What I am trying to do is to find each entry and delete it. Does not work - I have made many changes but either the program will not compile or the hash entries are still there
Can gurus help?
#!/usr/bin/perl
%messages = qw (1 342 2 4567 3 5999876 4 5768);
foreach $value (values (%messages)) > 5000000 {
delete $value.... #this is the line
}
print %messages, "\n";
I am sure that there is a better way to do it. AFAIK, there isn't a break available for a foreach loop to stop the looping when a $messages{$value} less than 5,000,000 is found.
That is a clever piece of code, man. Thanks a lot, man. BTW, I posted the same question on techrepublic.com and could not get any decent answers. That makes you a guru.
Just to kindle some good suggestion -
Does sorting here makes it a better solution, unless its an array and we are sure of the index, sorting a hash will not help us to escape from scannig each and every element of the hash.
so, basically I mean - even if you are sorting, you have to scan through each and every element of the hash.