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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.