[Webinar] Streamline your web hosting managementRegister Today


Convert a Perl CGI code to ASP

Posted on 2004-10-22
Medium Priority
Last Modified: 2010-08-05
I need to convert a Perl CGI script to ASP vb script, becuase I require to convert the data into my ASP program. and I have no idea about the CGI.

This is the CGI script

sub dc_decode {
    my $todecode = shift;
    return undef unless defined($todecode);
    $todecode =~ tr/+/ /;       # pluses become spaces
    $todecode =~ s/%([0-9a-fA-F]{2})/pack("c",hex($1))/ge;
    $todecode =~ s/\r\n/\n/g;;
    return $todecode;

Do anyone know the ASP version of the above script?
Question by:billson
  • 2
  • 2
LVL 28

Accepted Solution

sybe earned 1500 total points
ID: 12387606
in VBScript you can use the UnEscape() function for this.

MyVar = Unescape(Myvar)

But maybe you don't have to use this function at all. The perl function is used to convert a (url-encoded) querystring into something that was originally posted. I don't know in what context you need to use it, but in ASP, the querystring is automatically urldecoded when you ask individual items of the Request object.

So you will need to decode if you use the complete querystring

Response.write Unescape(Request.Quersystring)

But you don't need to decode for each formfield:

Response.write Request.Querystring("fieldname")

LVL 13

Expert Comment

ID: 12389204
Here is another alternative:

Author Comment

ID: 12392080
thx sybe  and StormyWaters, the return code is correctly display in ASP page, but if I use Windows Script Hosting - vbs file to get the output. the return code is mess-up. Any idea?
LVL 28

Expert Comment

ID: 12392093
What is the input you are giving to the Windows Scripting Host?

Author Comment

ID: 12394523
I have inputed Chinese character (BIG5 character set) and use the following script to encode in WSH, ASP also. ASP can return what I inputed. But WSH just return the "??" for those chinese character. I am using WinXP Chinese Traditional Version.

Since I need to convert 10000 message to the new asp system. I prefer to use WSH to prevent ASP timeout. But if no solution for WSH, I will try to use ASP to do so.

Function URLEncode(Text)
    Dim acode
    Temp = ""
    For i = Len(Text) To 1 Step -1
        acode = Asc(Mid(Text, i, 1))
            if (acode >= 48 AND acode <= 57) OR (acode >= 65 AND acode <= 90) OR (acode >= 97 AND acode <= 122) then
                  Temp = Mid(Text, i, 1) & Temp
            elseif acode = 32 then
                  Temp = "+" & Temp
                  Temp = "%" & Hex(acode) & Temp
            end if
      URLEncode = Temp
End Function

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
The video provides a quick and easy steps to migrate MBOX file to well known Outlook PST and Office 365. Besides this, it also supports and migrates more than 20 email clients of MBOX which include AppleMail, Opera, Thunderbird and SeaMonkey effortl…
Hi, this video explains a free download that you can incorporate into your Access databases, or use stand-alone for contact management. Contacts -- Names, Addresses, Phone Numbers, eMail Addresses, Websites, Lists, Projects, Notes, Attachments…
Suggested Courses
Course of the Month7 days, 14 hours left to enroll

607 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question