[Edinburgh-pm] Code cleanup

Aaron Crane perl at aaroncrane.co.uk
Mon Mar 5 14:30:53 PST 2012

Miles Gould <miles at assyrian.org.uk> wrote:
> On 05/03/12 17:24, Aaron Crane wrote:
>> lines 20, 22, 52: perhaps use <>  instead of manually opening the file
> My concern here is error reporting: you can get the name of the
> currently-open file from $ARGV, but $. increases across files. What's the
> best way round this?

`perldoc -f eof` suggests this:

while (<>) {
    # ...
continue {
    close ARGV if eof;


> Also, I don't know what's the correct behaviour for the
> program if it's handed several datasets - currently it ignores everything
> before the final "probes" line, which is almost certainly wrong.

… that's a good point.  Perhaps leave in the check that @ARGV is 1,
but still use <> for convenience.

>> lines 26, 76: inconsistent that these aggregates get an empty
>> initializer, when most don't (lines 25, 56, 57)
> What's best practice here - explicit initializers, or not?

I'd always avoid them — what could an array or hash without an
initialiser be initialised to if *not* an empty aggregate?  Including
them just seems like unnecessary clutter to me.

> Another question: what's the best way of getting the user to install all the
> dependencies? Add a Makefile.PL and tell them to run "cpan ."?

I'd recommend cpanminus rather than cpan, but yes, that's a pretty
simple option.

Aaron Crane ** http://aaroncrane.co.uk/

More information about the Edinburgh-pm mailing list