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.
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.
|