Hi Uri,

On Thursday 31 Mar 2011 01:19:15 Uri Guttman wrote:
> >>>>> "O" == Owen  <rc...@pcug.org.au> writes:
>   O> This will generate 10000 files in less than a second. They are 0 size,
>   O> so just write something into them if you don't wont zero sized files
> 
> might as well clean this up.
> 
>   O> #!/usr/bin/perl
>   O> use strict;
>   O> my $file = "/some/where/writeable/a1";
> 
>   O> my $j    = 0;
> 
>   O> for ( my $i = 1 ; $i < 10000 ; $i++ ) {
> 
> classic c loop. don't do c loops unless you must. they are not very
> perlish. perl loops are cleaner and faster:
> 
>       foreach my $i ( 1 .. 10000 ) {
> 

OK, one problem I can see here is the "magic number" / "magic constant" coding 
smell:

* http://perl-begin.org/tutorials/bad-elements/#magic_numbers

* 
http://en.wikipedia.org/wiki/Magic_number_%28programming%29#Unnamed_numerical_constants

The best way to overcome it is to assign it to a named constant, i.e:
"my $num_written_files = 10_000;" or with "use constant" or Readonly.pm (and I 
recall an alternative for that). It also seems to appear more than one time in 
the code which indicates some small amount of duplicate code (what if you'd 
like to add it later).

Also, Larry Wall has allowed Perl 5 numeric constants to contain underscore so 
you can write 10**9 as 1_000_000_000 instead of 1000000000 which is much less 
readable and also more error-prone. (Larry Wall)++ .

Regards,

        Shlomi Fish

-- 
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
My Public Domain Photos - http://www.flickr.com/photos/shlomif/

And the top story for today: wives live longer than husbands because they are
not married to women.
    -- Colin Mochrie in "Who's Line is it, Anyway?"

Please reply to list if it's a mailing list post - http://shlom.in/reply .

-- 
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