NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.
All the Perl that's Practical to Extract and Report
Stories, comments, journals, and other submissions on use Perl; are Copyright 1998-2006, their respective owners.
compact that code (Score:1)
Your code could be compacted quite a bit, if you change the calling syntax slightly and rely on the :)
while ()construct - and the surrounding perl magicSomething like the following
Re:compact that code (Score:1)
Re:compact that code (Score:1)
Well, there were a couple of points, some of them are probably a matter of personal taste/preferences ...
while ()' type of interface, meaning if I wanted to know the fog index of a string, I would pass it in via the shell withecho "string" | fog. This way the script behaves like a normal unix command line tool in that it can work as a filter for piping or be used to work on (one or more) files given on the command line. Thewhile ()was made for exactly that purpose so I try to use it whenever possible for my scripts. That results in the mentioned consistency - and makes the script even shorterwhile ()loop.while ()does that automatically for you (including the error messages and more (*))? Why is this handling of files written twice in the code?(*) The
while ()loop has built in error handling, it skips e.g. files (with an error message) that it can't open and continues processing the rest of the files.Reply to This
Parent