First, when you're iterating through a list, you don't have to keep an index around:
Next, you don't need to stringify a variable if you want to bind it to a regex.my @items = (1, 2, 3, 4, 5); foreach my $item (@items) { print "Got item $item!\n"; }
Third, there's a lot of duplication. From my skimming of the code, it's in your conditionals. There are plenty of ways to handle this, from stringing conditionals together to calling a subroutine. I'd do it all in just one regex, though:
You can probably get rid of the '+' in your opens. It's pretty rare that you need both read and write access. The rest of it is pretty solid, though you might want to be careful calling subs with a leading ampersand... it'll pass along the contents of @_. I prefer sub() to pass no arguments explicitly.if ($item =~ /^(foo|bar|baz)/) { # do several things }
Update: Renamed to fit new title.
In reply to Re: Document maintenance script
by chromatic
in thread Document maintenance script
by blacksmith
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |