The stupid question is the question not asked | |
PerlMonks |
Re: I know this code could be better...by jreades (Friar) |
on Jun 20, 2001 at 18:50 UTC ( [id://90017]=note: print w/replies, xml ) | Need Help?? |
Since this is apparently a constant, you might consider rewriting it as:
But if you want to be rigorous and good about preparing for when your script needs to do everything and run the kitchen sink, you might go so far as to write:
While your program remains simple , I believe that this will be inlined by the Perl compiler (so no performance hit), but if your program grows, such that lines might change depending on the context, you only have to rewrite the subroutine and everything else will work as expected. Actually, looking at your middle sub, I can't see any reason why you wouldn't just suck the file into a scalar and save yourself the overhead of array allocation:
To make things more reader-friendly and more extensible it's also a good idea to pass variables to your subs rather than simply calling variables declared elsewhere:
This sub now only makes the assumption that it should print whatever you've passed it... so now, it's re-usable and should probably be renamed print_to_user or some such. DISCLAIMER: I've been stuck as a Java programmer for the past few months so my Perl's getting more than a little rusty (trying to get involved again in Perlmonks), so not all of this stuff may perform as advertised. If so, then I apologize.
In Section
Seekers of Perl Wisdom
|
|