|Welcome to the Monastery|
Breaking down whole number into digitsby shevik (Initiate)
|on Nov 29, 2012 at 19:34 UTC||Need Help??|
shevik has asked for the
wisdom of the Perl Monks concerning the following question:
Hey guys, So I again, I come to the 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).
I understand the splitting part of it, I guess my issue is that fact that it's coming from a file and not <STDIN> this is my first time ever reading from a file. I don't know to access the contents of the file to split them.
My file is called x.txt but the program reads the file name from the keyboard so it could be whatever. The file contains a date, "21-Nov-1995" nothing else. I have gotten to the point to read the file in and I can print the "21-Nov-1995" I guess what I'm failing to pick up is what syntax I'm supposed to use when still trying to manipulate the file for splitting it.
Yes, this is for homework. I can edit it to my liking. As for the book I've read it, I stated I can read in the file in my 3 line of the original post, my apology for the lack of detail. I could go to the instructor and have. With no disrespect for the guy, his English isn't the best. Though anyway the following is what I'm using to open up my file.
the output does exactly as I'd hope after it's been opened, it prints the date 21-Nov-1995