1. Another Programming Question

Hey guys,

So I again, I come to the MMO-Champ forums looking for programming guidance. The language that I'm specifically trying to work with today is Perl. So pretty much for my class we're being asked to read in from a file, print out to a new file and use a sub routine for the program. With my knowledge of other programming languages (very limited mind you) I got everything done, except for my sub routine.

My subroutine is supposed to from the read in file take the input for example 21-Nov-1995 and break down the whole numbers into digits and then provide some computations.

so for example 21 = 2 and 1, Nov would be 1 and 1 etc etc.

After reading the chapters this project is supposed to cover I've found not one way to split the digits apart. to be honest the only way I can personally think of based on my past classes would be using a delimiter and even then we haven't covered that in this class yet. So I guess there's a way to do it otherwise?

Any guidance of just how to split up my whole number would be really appreciated (any method or example would do honesty).

Thanks, Shevik

2. I don't know how to program in Perl, but I'm sure there's a way to read in the values as a string, then splice it up into individual tokens.

3. I didn't really understand if you are having trouble splitting the original string, or splitting the whole number into digits.

If it is the original string you are having trouble with, then you have already answered your own question. In the example you gave, "21-Nov-1995" has the character "-" as a delimiter. Here is the Perl function that would split that, with some examples that relate to your question: http://perldoc.perl.org/functions/split.html

If it's the whole-number-to-digits you are having trouble with, which I believe it is, then you basically need to solve it mathematically. I'm not going to give you the code because that is probably the whole point of your assignment and you should be able to come up with the code yourself, but the algorithm revolves around recursively dividing your whole number by 10. Example:

First iteration:
1995/10 = 199
1995%10 = 5

Second iteration:
199/10 = 19
199%10 = 9

And so on.

Posting Permissions

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