|more useful options|
Functions in Perlby bluethundr (Pilgrim)
|on May 23, 2004 at 00:13 UTC||Need Help??|
bluethundr has asked for the
wisdom of the Perl Monks concerning the following question:
I just learned how to treat functions in Perl using Laura Lemay's "Perl In 21 Days" by Sams. The question was on p.272 of that tome and exercise one states:
Write a subroutine that does nothing but print its arguments, one argument per line, with each line numbered.
Now some clarification: Lemay's attitude is that if it is an imported function or one that is part of perl itself one refers to it as a "function". If it is one that you write yourself, it's what she refers to as a "subroutine". This was just her writing style, and says that one can refer to them as either and you'll still be right from a comp sci. standpoint.
I do plan on getting merlyn's book (as has been suggested) as well as the O'Reilly one by St. Wall. But in the meantime I am getting my toes wet with Lemay's book. One step at a time, eh?
Well anyway, here is how I approached the problem. I hope you goes don't mind me asking this everytime I give myself an assignment! But I would love to see how a more experienced programmer would do things. I am still studying my earlier thread, btw which generated and INCREDIBLE response for which I am grateful. Here goes:
Now I know that I may have separated some things out into their own functions that maybe I shouldn't have. That's the sort of thing I would love to recieve criticism on. Also, I got some feedback on one of my earlier posts that I should use 'strict', etc. I totally agree with that viewpoint! But I haven't "book learned" these concepts yet! I'm sure I'll get to them eventually. But at my toddler's level on perlness at the moment, I think I can afford to leave certain things till later when I learn about them.