in reply to Re^8: Thread on Joel on software forum : "I hate Perl programmers."
in thread Thread on Joel on software forum : "I hate Perl programmers."
Probably just an oversight in posting, but there is a problem with this:
# build the grid my @grid; my @row = qw/01 02 03 04 05 06 07 08 09 10 11 12/; for (1..$NUMBER_OF_ROWS) { push @grid, \@row; }
#! perlmy @grid; use strict; use Data::Dumper; use constant NUMBER_OF_ROWS => 12; my @grid; my @row = qw/01 02 03 04 05 06 07 08 09 10 11 12/; for (1..NUMBER_OF_ROWS) { push @grid, \@row; } print Dumper \@grid; __END__ $VAR1 = [ [ '01', '02','03', '04', '05', '06', '07', '08', '09', '10', + '11', '12' ], $VAR1->[0], $VAR1->[0], $VAR1->[0], $VAR1->[0], $VAR1->[0], $VAR1->[0], $VAR1->[0], $VAR1->[0], $VAR1->[0], $VAR1->[0], $VAR1->[0] ];
I made the same mistake initially by coding
my @grid = ( [ '01' .. '12' ] ) x 12;
This is being addressed in p6 by a new operator (which I cannot remember if it is 'xx' or 'xxx', but the effect is to iterate it's left operand, not replicate it. (As far as I understand it).
It has become my "standard conversion" for where I want to type
my @grid = ( .... ) x $n;
but need new instances instead of replicated references to exchange the 'x' operator for map:
my @grid = map{ ... } 1 .. 12;
I appreciate your misgivings about the 1 .. 12, but that is (as it's position on the right-hand side tends to denote (to my brain) the lesser suboperation of the significant operation; namely that I am initialising the array grid with separate instances of some constant expression. (Oh. And there are 12 of them :).
Beyond the thinko, the problem I have with the for/push method is that the main objective--that of initialising the array @grid--gets lost in the noise of the construction.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^10: Thread on Joel on software forum : "I hate Perl programmers."
by Aristotle (Chancellor) on Nov 30, 2005 at 17:21 UTC | |
by BrowserUk (Patriarch) on Nov 30, 2005 at 17:53 UTC | |
by Aristotle (Chancellor) on Nov 30, 2005 at 19:41 UTC |