Professional Web Applications Themes

Help translate into Perl - PERL Beginners

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 ...

  1. #1

    Default Help translate into Perl

    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
    =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

    Mike Guest

  2. #2

    Default Re: Help translate into Perl

    On Jul 16, 2004, at 4:51 PM, Mike Blezien wrote:
     

    What have you tried?

    We will help you when you get stuck, but we won't write it for you. ;)
    If you need to hire a Perl Programmer, please do so.

    James

    James Guest

  3. #3

    Default Re: Help translate into Perl

    James Edward Gray II wrote: 
    >
    >
    > What have you tried?
    >
    > We will help you when you get stuck, but we won't write it for you. ;)
    > If you need to hire a Perl Programmer, please do so.
    >
    > James[/ref]

    I am try to decifer it now, but all I was looking for is just maybe a little
    help translating it as to what it's attempting to do, not actually write out any
    coding. Just a basic breakdown. The perl coding I can do myself.

    --
    Mike<mickalo>Blezien
    =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    Thunder Rain Internet Publishing
    Providing Internet Solutions that work!
    http://thunder-rain.com
    =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

    Mike Guest

  4. #4

    Default RE: Help translate into Perl

    From: Mike Blezien <mailto:net> wrote:

    : James Edward Gray II wrote:
    : : On Jul 16, 2004, at 4:51 PM, Mike Blezien wrote:
    : :
    : : : 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.
    : :
    : : What have you tried?
    : :
    : : We will help you when you get stuck, but we won't write it
    : : for you.
    : : ;) If you need to hire a Perl Programmer, please do so.
    :
    : I am try to decifer it now, but all I was looking for is just
    : maybe a little help translating it as to what it's attempting
    : to do, not actually write out any coding. Just a basic
    : breakdown.

    The pseudo code is generating a key based on the value of
    a user ID. The instructions are fairly straight forward. It
    seems pretty easy to write the perl code directly from them.
    Which parts are you having trouble understanding?


    HTH,

    Charles K. Clarkson
    --
    Mobile Homes Specialist
    254 968-8328

    Charles Guest

Similar Threads

  1. Question translate xml file into hash table using perl
    By veerubiji in forum Perl / CGI
    Replies: 0
    Last Post: September 30th, 12:00 PM
  2. Replies: 2
    Last Post: September 19th, 03:48 AM
  3. please translate
    By Mykoo in forum Macromedia Flash Actionscript
    Replies: 0
    Last Post: February 24th, 02:06 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139