Link to home
Start Free TrialLog in
Avatar of billson
billson

asked on

Convert a Perl CGI code to ASP

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?
ASKER CERTIFIED SOLUTION
Avatar of sybe
sybe

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of billson
billson

ASKER

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?
What is the input you are giving to the Windows Scripting Host?
Avatar of billson

ASKER

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
            else
                  Temp = "%" & Hex(acode) & Temp
            end if
    Next
      URLEncode = Temp
End Function