in reply to Critique of some perl code.
To be honest, I don't consider this code that bad. Yes, there are some small issues - they mainly suggest the author is not a perl expert - but it seems unlikely that any of them would affect correct behaviour or cause significant performance issues in the context this code is likely to run.
My first concerns would rather be with two things you don't mention: that on failing to open the file for reading (most likely due to permissions), it fails to mention the name of the file it tried to open; and that it stuffs @ARGV with an arbitrarily long list of the words it found, which feels like a possible design flaw.
That last, however, suggests this configuration file is expected rarely to be more than a couple of lines long, so performance of the processing loop is really not likely to be very relevant.
Data is assigned to $_ and then copied to $line but $_ is never used inside the loop.
This is pretty reasonable if as a non-expert you are vaguely aware that while ($line = <$fh>) has some differences around termination conditions compared to while (<$fh>).
This is the line that gobsmacked me. I ran some tests with Benchmark and re 'debug' compared to the FAQ answer "s/\s+$//;" and it turns out that this is a good example of what not to do.
And how much CPU time do you think replacing it would save over the lifetime of the universe? I suspect the total would sit comfortably under a second, maybe even under a millisecond.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Critique of some perl code.
by Fletch (Bishop) on Apr 18, 2022 at 14:30 UTC | |
by afoken (Chancellor) on Apr 21, 2022 at 07:26 UTC | |
by Fletch (Bishop) on Apr 21, 2022 at 16:54 UTC | |
Re^2: Critique of some perl code.
by jwkrahn (Abbot) on Apr 18, 2022 at 03:00 UTC | |
by AnomalousMonk (Archbishop) on Apr 18, 2022 at 05:41 UTC | |
by hv (Prior) on Apr 18, 2022 at 17:32 UTC | |
Re^2: Critique of some perl code.
by jwkrahn (Abbot) on Apr 17, 2022 at 19:30 UTC |