Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

When constructing a URL from script variables, how do I handle spaces properly?

by rodry (Beadle)
on Apr 28, 2000 at 23:44 UTC ( #9624=perlquestion: print w/replies, xml ) Need Help??

rodry has asked for the wisdom of the Perl Monks concerning the following question:

I have a script that will construct a link to another PERL script and pass it parameters based on a column returned by a query.
There is a problem however. This column that I am passing as a parameter may or may not have spaces in it. More than likely it will have spaces.
So my question is: how do I detect this spaces and replace them with the appropiate ASCII character code.
As an alternative, how do I filter the user input when providing values for this column so that it will eliminate the spaces, if any?
Thanks in advance

Originally posted as a Categorized Question.

  • Comment on When constructing a URL from script variables, how do I handle spaces properly?

Replies are listed 'Best First'.
Re: When constructing a URL from script variables, how do I handle spaces properly?
by merlyn (Sage) on Apr 30, 2000 at 16:01 UTC
    In fact, if you are trying to construct
    <a href="/cgi-bin/editmarine.pl?marine=$marineid">edit marine</a>
    You'll run into a lot of problems if $marine is not URI-encoded. So the first step is to trot over to URI::Escape and run it through there. No spaces will be left!

    Editor's note:

    #Sample Code my $SafeMarine = URI::Escape::uri_escape($marineid); <a href="/cgi-bin/editmarine.pl?marine=$SafeMarine">edit marine</a>
      I've also used the code below to replace spaces with the correct chars.
      $value =~ s/\s/\%20/g;
      And it seems to work good for my purposes.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://9624]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2021-09-28 01:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?