Convert a Perl CGI code to ASP

Posted on 2004-10-22
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
    LVL 28

    Accepted Solution

    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

    Here is another alternative:
    LVL 1

    Author Comment

    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

    What is the input you are giving to the Windows Scripting Host?
    LVL 1

    Author Comment

    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Suggested Solutions

    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…
    Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    911 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

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now