Contributed by Anonymous Monk
on Aug 02, 2000 at 00:08 UTC
Q&A
> CGI programming
Description: This one has me baffled. I am getting the following result
from using $cgi_obj->escape("some_value"):
CGI=HASH(0x1d7820)
This is NOT what anyone would normally expect from a call to
escape, and unescape produces similar output. My key
difference is that I'm on a Sun machine running SunOS 5.6
(it appears from running 'uname') whereas I've never had
this problem on linux or windows. Any body care to comment?
Thanks.
Mike Answer: My parameters can't escape from the Sun... contributed by davorg I think this is a problem with older versions
of CGI.pm. In older versions on the module (and
I can't remember when it changed) the
escape subroutine didn't have a OO
interface, so it expected its first parameter
to be the string to be escaped.
By calling it with an OO interface, as you
have, you give it the CGI object as the first
parameter. escape tries to URL encode
that object and returned the URL encoded version.
When you print out the return code, you the
string representation of the object, which is
the type and reference - hence the output you
see.
Solutions: 1/ Get a more recent version of
CGI.pm. 2/ Call escape using the
functional interface like this:
$escaped = escape('some text');
| Answer: My parameters can't escape from the Sun... contributed by autark Maybe you are trying to interpolate method calls in strings?
Unfortunatly, function- and method calls will not interpolate
in strings. So you might try something like this instead:
print "Got: ", $cgi->escape("some_value"), "\n";
Well, you can do something like the following, but I
don't think it's pretty:
print qq(Got: @{[ $cgi->escape("some_value") ]}\n);
Autark |
Please (register and) log in if you wish to add an answer
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Outside of code tags, you may need to use entities for some characters:
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
|
|