EvanK has asked for the wisdom of the Perl Monks concerning the following question:
I'll likely end up with three different name-value strings (in the standard "name=value&name=value" form). I want to access all this data through a CGI object, *but* I'd like GET data to take precedence over POST data, which should take precedence over cookie data, and I can't be sure of the results of just joining them and passing the result to new CGI($str).
So basically, I want to Thus if I end up with these values:
I need to merge them into this:$cookie = "user=john&pass=bleh&sort=descending"; $post = "pg=2&col=3&row=4"; $get = "pg=1&sort=ascending";
Is there an obvious and/or more efficient way to do this that doesnt require breaking everything down into hashes and processing it all several times (because these strings may get very large)?$str = "user=john&pass=bleh&pg=1&col=3&row=4&sort=ascending";
Addendum: Basically, I know i could split into an array on '&', and then split each element on '=' into hash keys/values, and do cookie, post, get (so newer vals overwrite existing vals), but is there a better way?
__________
Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
- Terry Pratchett
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: merging multiple name-value pairs (with precedence)
by davidrw (Prior) on Feb 09, 2006 at 14:53 UTC | |
by EvanK (Chaplain) on Feb 09, 2006 at 15:02 UTC | |
|
Re: merging multiple name-value pairs (with precedence)
by blokhead (Monsignor) on Feb 09, 2006 at 15:14 UTC | |
by EvanK (Chaplain) on Feb 09, 2006 at 22:25 UTC |