PDA

View Full Version : Retain Spaces in field value


lmayer4
09-27-2006, 03:08 PM
Morning,

I have a value I'm trying to pass from a form in a cookie. The first
time it's passed it shows up as "North Hall A" but when a user is sent
back to the page the value changes to "North"


I set the cookie like:


my $cookie_id = param('Building');


my $cookie = cookie(-name => 'Building',
-value => $cgi->param('Building'),
-expires => '+3d');



and then reference it like $cookie_id. In PHP I know I can use
urlencode to preserve the spaces but I can't find out how perl does it.


Thanks for any help.


AJ

rwedge
09-28-2006, 03:41 AM
One way to encode a string in Perl is:$cookie_id = 'North Hall A';
$cookie_id =~ s/([^A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg;
print $cookie_id;output: North%20Hall%20A

KevinADC
09-28-2006, 06:43 AM
Yes, there is no perl function urlencode() like in PHP. You can use the URI::Escape module (would probably need to be installed) or a regexp like rwedge posted.

http://search.cpan.org/~gaas/URI-1.35/URI/Escape.pm