hello,
I have been given some programming code that I need to convert or translate into perl coding, and I was hoping someone on this list maybe able to help me out. I have a vague idea what it's suppose to be doing, but some of it isn't real clear. Below is the psuedo-code sample
##### START CODING ##########
str* are strings
num* are some type of numerics, typically integers
The algorithm needs basic functions like right(), left(), mid(), concatenate(), ASCII(), and
modulus. modulus is non-negative mod(7, 4) = 3 NOT -1.
validate userID is greater than 3 characters and all ASCII character
set. Else, return error than invalid userID has been entered. Is it possible to do this?
# trim length of strUserID less than or equal 10 characters
# if strUserID is greater than 10 characters, then concatenate the 5 leftmost and 5 rightmost
# into one string
# else, do nothing
numLengthUserID = length(strInitialUserID)
if length(strUserID) > 10
strFinalUserID = (left(strInitialUserID, 5) & right(strInitialUserID, 5))
numLengthUserID = 10
else
strFinalUserID = strInitialUserID
# Initial values strC = "" numC = 0 numKey = 0 strKey = "00000" i = 0
# loop over the string strFinalUserID one character at a time # increment the loop counter, i, as you go for i = 0, i < numFinalUserID
# extract the ith character from the string strFinalUserID strC = mid(strFinalUserID, i, 1)
# put the ASCII value of strC into numC numC = asc(strC)
# create a registration number key based on numC and i # note: mod is the non-negative modulus function; often % numKey = (numKey + (4 * numC * (mod(i, 2)))) numKey = (numKey + (5 * numC * (mod(i, 3)))) numKey = (numKey + (6 * numC * (mod(i, 4)))) numKey = (numKey + 11) next i
# take the modulus of key to return a value between 0 and 65536 # that is, if numKey = 96689, mod(numKey, 65536) = 31153 numKey = mod(numKey, 65536)
# pad the registration key string to 5 characters with leading 0's # that is, if numKey = 9876, strKey = "09876" strKey = format(numKey, "00000") ##### END CODING ############################
TIA
-- Mike<mickalo>Blezien =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Thunder Rain Internet Publishing Providing Internet Solutions that work! http://thunder-rain.com =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>