On 8/8/01 7:08 PM, Dianne Van Dulken wrote:

> Hi All, 
> 
> I am having a little trouble with a regexp and I was hoping I might get a
> hint towards a module or something like that.
> 
> I get a query string passed to me, that I need to record in a database.  A
> typical one might look like this:
> 
> %3Cdel_phone%3E%28020%200202%2000202%3C/del_phone%3E
> 
> etc.
> 
> I am sure that the problem is pretty obvious to you straight away.  I have a
> regexp to change %3C to <, %3E to >, %20 to a space, etc, but I keep on
> finding characters that I wasn't expecting, and I am sure that somewhere out
> there, there must be a place that has a list of all of these characters or a
> module to convert them.  I searched on perl.com, but couldn't find anything
> that seemed to match this problem
> 
> Any ideas?  I just need to be pointed where to look
> 
> Cheers
> 
> Di
> 
> --
> Dianne van Dulken
> E-commerce Analyst/Programmer
> OzEmail
> Phone: (02) 9433 2510

Hi,

>From your example, it appears that you simply need to parse a URL-encoded
string. For that, you could use this regex, which uses the chr and hex
functions to translate URL-encoded characters:

$string =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg;

(this produces "<del_phone>(020 0202 00202</del_phone>" from your example
string).

However, if you are getting GET or POST input and wish to parse it, I
strongly recommend that you use the built-in module CGI.pm. If this is the
case, you could do it like this (see the CGI.pm documentation for a better
description):

use CGI;
$query = new CGI;              # create a new query object.

@values = $query->param;       # assign @values to the names of all the
                               # keys in $query

$value = $query->param('foo'); # assign $value to the value of "foo"


Hope that helps.

-Michael Kelly
Email: [EMAIL PROTECTED]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to