kanji is right, of course. CGI.pm will make your life much easier here. It deals with the problem you're facing, and with a hundred more that haven't come up yet and never will if you adopt it now...
To answer your question, for once, here's a modified version of what i use for paging back and forth. it normally lives in a List class, so this is a bit hacked out and has all its sanity-checks removed:
use CGI; my $query = new CGI; my $slice = $query->param('slice'); my $next_qs = build_qs($query, slice => $slice + 1); sub build_qs { my ($query, %new_param) = @_; my %parameters = map { $_ => $query->param($_) } $query->param; $parameters{$_} = $new_param{$_} for keys %new_param; return join '&', map { "$_=$parameters{$_}" } keys %parameters; }
In this example, $next_qs will contain the query string you need to append your script address to get the next page up.
build_qs($cgi_object, %hash) will return a query string which is exactly the same as the one supplied to the script except that any name => value pairs you supply in the %hash will be used instead of (or in addition to) the present input. the generalisation will be useful when you start wanting to change list order and length as well.
I'm sure there's a more elegant way to do the building part - someone will probably supply a one-liner that uses CGI.pm properly - but this works for me.
In reply to Re: Need to create a pre and post string from a REQUEST_URI
by thpfft
in thread Need to create a pre and post string from a REQUEST_URI
by S_Shrum
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |