in reply to Pesky little URL files to HTML
Even if that's too concise for you (localizing a glob automagically closes a filehandle when the glob goes out of scope, some people hate returning from within a loop, some people need to see an if there, though it deparses to the same thing), there's no need of doing a match and then a substitution. s/// has a return value for a reason. :) I do much prefer returning things than printing from within a function.sub filter { my $file = shift; local *FILE; open FILE, $file or die "Couldn't open: $file $!\n"; while(<FILE>) { s/BASEURL=// and return qq|<li><a href="$_">$_</a></li>\n|; } }
expand() could also be shorter:
You'll need to call it as @ARGV = expand(@ARGV);, or just do it all in place.sub expand { map { bsd_glob($_) } @_; }
Of course, we could end up with:
It gets a little ridiculous, optimizing beyond that point. Still, you *could* do it that way.print "<ul>\n", map { filter($_) } map { bsd_glob($_) } @ARGV, "\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Pesky little URL files to HTML
by hsmyers (Canon) on Dec 17, 2001 at 06:54 UTC | |
by chromatic (Archbishop) on Dec 17, 2001 at 07:33 UTC |