You are viewing a plain text version of this content. The canonical link for it is here.
Posted to embperl@perl.apache.org by Leon Brocard <le...@iii.co.uk> on 2000/06/07 13:10:17 UTC

Dynamic URI query strings

Heya,

I coming across a problem and I'm hoping that someone has solved it
in a slightly cleaner way than I have.

We have Embperl pages which include Embperl "components". These
components need to link to the same pages but with additional parameters
(intended for the component) passed in the URL. [The components
are done with Execute($name, \%conf)]

ie the page is called with:
/investment/detail.epl?code=FOO&display=WOTSIT&it=BAR
but the component wants to link to:
/investment/detail.epl?code=007&display=WOTSIT&it=BAR&new=YES

The way I have done it is for the page to pass the component
a "prefix" URI, which the component then manipulates. I haven't
found a Perl module which'll do what I want, so I've had to come
up with the following which uses the CGI and URI modules:

my $uriprefix = '/investment/detail.epl?code=FOO&display=WOTSIT&it=BAR';
my $uri = URI->new($uriprefix);
$uriprefix = $uri->query();
my $q = CGI->new($uriprefix);
$q->param('code', '007');
$q->param('new', 'YES');
$uriprefix = $uri->path . '?' . $q->query_string;
print $uriprefix, "\n";

Have I missed something? Is there a module on CPAN which makes this
manipulation easier? Should there be?

Cheers, Leon
--
Leon Brocard   |   perl "programmer"   |   leon.brocard@iii.co.uk

RE: Dynamic URI query strings

Posted by Gerald Richter <ri...@ecos.de>.
> 
> my $uriprefix = '/investment/detail.epl?code=FOO&display=WOTSIT&it=BAR';
> my $uri = URI->new($uriprefix);
> $uriprefix = $uri->query();
> my $q = CGI->new($uriprefix);
> $q->param('code', '007');
> $q->param('new', 'YES');
> $uriprefix = $uri->path . '?' . $q->query_string;
> print $uriprefix, "\n";
> 

Why don't you simply append to the string? Am I missing something?


my $uriprefix = '/investment/detail.epl?code=FOO&display=WOTSIT&it=BAR';
$uriprefix .= '&code=007&new=YES';
print $uriprefix, "\n";

Gerald