in reply to Re: Re: Handling Dynamic URL Parameters
in thread Handling Dynamic URL Parameters
This checks for zero or more of any character followed by 2 occurances of either ?:~.+The (?: ... ) construction is 'pure grouping.' So (?:~.+){2} matches, but does not assign to a variable, a tilde ~ followed by one or more chars twice.... basically checking for 2 tildes. Somebody else could write this more elegantly, I'm sure.
Here's an example querystring. I'll use the names that shotgunefx suggested.
Since now we're dealing with fields with 2 and 3 ids, we need to adjust the code some.?item~1~name=boobtube&item~1~qty=1&item~1~code=mysqlpk&item~2~name=loo +sifer&item~2~qty=1&item~2~code=666&ship~firstname=Han ...
Is this a better example?# Always use warnings; use strict; use CGI; my $q = CGI::new; my %lineitem; my %ship; # process params # for my $param ( $q->param ) { my @id = split(/~/,$param); # a SWITCH would work nicely, but I'll try # not to confuse the example if ( $id[0] eq 'item' ) { $lineitem{$id[1]}{$id[2]} = $q->param($param); } if ( $id[0] eq 'ship' ) { $ship{$id[1]} = $q->param($param); } } # process lineitems # print "Please confirm order of<br/> "; for my $item ( keys %lineitem ) { print $lineitem{$item}{qty}, $lineitem{$item}{name}; print "<br/>"; } print "<br/>being shipped to $ship{firstname}<br/>";
(Edit: minor spelling and grammer fixes)
(Edit: replaced my ($id1,$id2,$id3) = with my @id =)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re3: Handling Dynamic URL Parameters
by the_Don (Scribe) on Sep 13, 2002 at 18:14 UTC |