CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Need help converting Java to Perl

 



AndrewG
stranger

May 21, 2002, 1:28 PM

Post #1 of 2 (410 views)
Need help converting Java to Perl Can't Post

Greetings,

I'm trying to convert the following Java script to Perl.


Code
 
function ccc18(form) {
factor = 3;
sum = 0;
for (index = form.numero.value.length; index > 0; --index) {
sum = sum + form.numero.value.substring (index-1, index) * factor;
factor = 4 - factor;
}
cc = ((1000 - sum) % 10);
form.cc.value = cc
if (form.numero.value.length!=17){
alert("Invalid # please contact Customer Service for assistance at 937-435-3870")
form.cc.value = "";
}

}



#!/usr/local/bin/perl

$factor = "3";
$sum = "0";
$value = "00053329000000748";


for ($index = 17; $index > 0; $index--) {
$sum = $sum + $value * $factor;
$factor = 4 - $factor;
}


$cc = ((1000 - $sum) % 10);

print $cc;



I am having a problem when I try to get (index-1, index) to work. The output of the perl script should be 9.

You can see an example of the working java script here.

http://www.uc-council.org/checkdig.htm (SSCC)



TIA Wink

Andrew


yapp
User

May 23, 2002, 12:33 PM

Post #2 of 2 (407 views)
Re: [AndrewG] Need help converting Java to Perl [In reply to] Can't Post

You can use the substr (and the length) operations/functions in Perl to get the same result.

IN the perldoc tool, you''ll find info about these functions, or take a look at that perldoc website

Yet Another Perl Programmer

_________________________________
~~> [url=http://www.codingdomain.com]www.codingdomain.com <~~
More then 3500 X-Forum [url=http://www.codingdomain.com/cgi-perl/downloads/x-forum]Downloads! Cool

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives