Web Analytics Made Easy -
StatCounter Retain Spaces in field value - CodingForum

Announcement

Collapse
No announcement yet.

Retain Spaces in field value

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Retain Spaces in field value

    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:

    Code:
    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

  • #2
    One way to encode a string in Perl is:
    Code:
    $cookie_id = 'North Hall A';
    $cookie_id =~ s/([^A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg;
    print $cookie_id;
    output: North%20Hall%20A

    Comment


    • #3
      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

      Comment

      Working...
      X