Gossamer Forum
Home : General : Perl Programming :

How to empty %in values from a form?

Quote Reply
How to empty %in values from a form?
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:

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?
Quote Reply
Re: [ecn] How to empty %in values from a form? In reply to
 

Cheers,

Dat

Programming and creating plugins and templates
Blog
Quote Reply
Re: [ecn] How to empty %in values from a form? In reply to
If you are undeffing %in then you are totally undefining %in as if it never existed and so there must be some part of your code that is doing something it shouldn't be.

I don't see anything obvious in the code. It may be best to work line by line through the code to check all the values of hashes and variables to see what's doing what.
Quote Reply
Re: [ecn] How to empty %in values from a form? In reply to
Hi,

Is this what you want?

#my %ori = map{$_ => $in{$_}} keys %in;

#undef %in;
# %in = map{$_ => $newhash{$_}} keys %newhas;
# do something
# undef %in
# retore %in
#%in = map{$_ => $ori{$_}} keys %ori;
#

Hope that helps

Cheers,

Dat

Programming and creating plugins and templates
Blog
Quote Reply
Re: [tandat] How to empty %in values from a form? In reply to
Quote:
my %ori = map{$_ => $in{$_}} keys %in;

That is exactly the same as:

my %ori = %in;