in reply to I know this code could be better...
my $links = 'h:\perl scripts\links.txt';
Since this is apparently a constant, you might consider rewriting it as:
my $LINKS = 'h:\perl scripts\links.txt';
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:
sub LINKS { return 'h:\perl scripts\links.txt'; }
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:
undef $/;
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:
sub middle { my @output = @_; print while @output; }
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: I know this code could be better...
by petdance (Parson) on Jun 20, 2001 at 22:41 UTC | |
by jreades (Friar) on Jun 21, 2001 at 01:16 UTC | |
|
Re: Re: I know this code could be better...
by Kevman (Pilgrim) on Jun 21, 2001 at 14:02 UTC |