Cody Pendant has asked for the wisdom of the Perl Monks concerning the following question:
I've got the old list of which ones are true or false, and I've edited it using a web form, probably removing some from the "true" list and adding others to it.
Having submitted the form, what's the best way to reset the list correctly?
I did it like this:
I made a hash of 100 entries all set to zero, then did a foreach on the list of old items, and set the right values to 1.
Then I made a hash of 100 entries all set to zero and did a foreach loop on the list of new items, setting the right values to 1.
Then I went through the hash keys like this:
foreach $entry(@a){ if ($oldhash{$entry}==1 && $newhash{$entry}==0){ # push it into an array of deletions to be made } elsif($newhash{$entry}==1 && $oldhash{$entry}==0){ # ditto array of additions to be made } }
I've been staring at this code for a while and I can't figure out if that's a dumb way to do it or not, but it feels kind of dumb.
Is there a smarter way?
--
Edit: chipmunk 2002-02-24
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: comparing two hashes
by chipmunk (Parson) on Feb 24, 2002 at 06:24 UTC | |
by rinceWind (Monsignor) on Feb 24, 2002 at 22:14 UTC | |
by Cody Pendant (Prior) on Feb 24, 2002 at 23:16 UTC | |
by screamingeagle (Curate) on Feb 25, 2002 at 03:09 UTC | |
|
Re: comparing two hashes
by Cody Pendant (Prior) on Feb 25, 2002 at 00:13 UTC |