On 10/12/2011 13:04, Shlomi Fish wrote:
Hi,

On Fri, 09 Dec 2011 20:44:18 +0000
Rob Dixon<rob.di...@gmx.com>  wrote:

On 09/12/2011 11:35, flebber wrote:
With this program

    @data =<ARGV>;
    $sum += $_ for @data;
    print $sum / @data;


This program:

1. Does not have "use strict;" and "use warnings;".

2. Collects all lines in one giant array (which is a waste of memory.).

3. Does not do exactly match the original program.

It can and should be written better.

All that put aside, I think it's possible that giving full programs as
answers to people's questions here may be detrimental to the process of
helping them, because they will just use that program, instead of learning
how to properly write the code themselves.

I agree with you of course. It also rather cheekily avoids chomping the
records read from the file as it works fine anyway. You are aware that I
always insist on 'strict' and 'warnings' where applicable, but even I
wouldn't object to leaving them out on a three-line program. The
solution was meant as a thought-provoker, but I rather think you
wouldn't have raised an eyebrow if I had published

  perl -e "@d=<ARGV>;$s+=$_ for @d;print $s/@d" m.txt > report.txt

instead. One-liners seem to be immune from all recognized good practice!

Rob

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to