I failed to mention that I cannot replace existing parameters with the new one I am appending. The above code does this. So I have written the below which appears to work:
use strict;
use URI::URL;

sub addEnvVar ($$$$)
{
    my $URL = shift;
    my $name = shift;
    my $value = shift;
    my $returnRef = shift;

    # Create the URL as an object and extract already existing parameters.

    my $url = new URI::URL ($URL);
    my $qstring = $url->equery ();

    # Split the parameters up.

    my @params = split (/\&/, $qstring);

    # Split the name=value pairs up and place them in a parameter list.

    my @paramList;
    foreach my $param (@params)
    {
	my ($pname, $pvalue) = split (/\=/, $param);
	push (@paramList, $pname);
	push (@paramList, $pvalue);
    }

    # Add the new parameters to the end of the list.

    push (@paramList, $name);
    push (@paramList, $value);

    # Place the parameter list in the URL.

    $url->query_form (@paramList);

    # Get the resulting URL after appending the new variable.

    my $newURL = $url->as_string ();
    $$returnRef = $newURL;

    return 1;
}

The only minor problem I had testing this occurred when I tried to have parameters such as:
   carr%20ots=cooked
These would appear in the resulting URL as:
   carr%2520ots=cooked
But I'm not sure if its even legal to have such things in
parameters.  I think I'll stick with this for now.
Thanks a lot for your help,

Leigh

In reply to Re: •Re: Adding param to a specified URL by Anonymous Monk
in thread Adding param to a specified URL by maltesehamster

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.