I must be doing something wrong. I have some key value pairs, originally part of a form submission (a simple database search), that are stored in a hash called %in.
I'd like to empty the %in hash, storing its key-values in %in_current, so that I can use %in for something else for a while (namely, an internal search of the database, based on the terms of the user's search).
Then I'd like to move the %in_current values back into %in, and print the record the user requested.
So I send some new key-values into a subroutine as %inhash. Then:
%current_in = %in;
undef %in;
# creates new, temporary %in with values from %inhash
while (($key, $value) = each (%inhash)) {
push(@invalues, $key, $value);
}
%in = @invalues;
Here, the search function is called, its results printed, and then:
# attempt to restore the current %in values
undef %in;
%in = %current_in;
And we go on our merry way, printing the results of the original search. Only problem is, the %in key-values seem to pile up, contaminating the second set of results, those originally called by the user. It seems like %in is holding on to both sets of key-value pairs (the user set and the internal set).
Is there a better way to temporarily clear the %in values and then restore them? What am I missing here?
I'd like to empty the %in hash, storing its key-values in %in_current, so that I can use %in for something else for a while (namely, an internal search of the database, based on the terms of the user's search).
Then I'd like to move the %in_current values back into %in, and print the record the user requested.
So I send some new key-values into a subroutine as %inhash. Then:
Code:
%current_in = %in;
undef %in;
# creates new, temporary %in with values from %inhash
while (($key, $value) = each (%inhash)) {
push(@invalues, $key, $value);
}
%in = @invalues;
Here, the search function is called, its results printed, and then:
Code:
# attempt to restore the current %in values
undef %in;
%in = %current_in;
And we go on our merry way, printing the results of the original search. Only problem is, the %in key-values seem to pile up, contaminating the second set of results, those originally called by the user. It seems like %in is holding on to both sets of key-value pairs (the user set and the internal set).
Is there a better way to temporarily clear the %in values and then restore them? What am I missing here?