Christoph Friedrich wrote:
Hello there,
Hello,
I am new to Perl and I am not sure if my Coding Style is good.
Could some of you please check if my Coding Style is good or tell me
what I should change to get a good Coding Style?
You can find 2 files of my current project under
http://www.christophfriedrich.de/code/
Please check it so that I can write good code on bigger projects.
# Initialise allowed array to all numbers allowed
for (my $i = 1; $i <= $size; $i++)
That is usually written as:
for my $i ( 1 .. $size )
{
$self->{'allowed'}[$i] = 1;
}
In Perl arrays start at 0 so you are skipping $self->{'allowed'}[0] in
your initialization.
You can do that without a loop like:
$self->{ allowed } = [ ( 1 ) x $size ];
Or:
@{ $self->{ allowed } } = ( 1 ) x $size;
# Initialise cells
for (my $row = 1; $row <= $size; $row++)
That is usually written as:
for my $row ( 1 .. $size )
{
$cells[$row] = ();
What do you think that you are assigning to that scalar value? That
makes no sense.
for (my $col = 1; $col <= $size; $col++)
Same as above:
for my $col ( 1 .. $size )
{
$cells[$row][$col] = DragonNet::Games::Sudoku::Board::Cell->new(size
=> $size);
In Perl arrays start at 0 so you are creating an array of ( $size + 1 )
* ( $size + 1 ) with nothing in row 0 or column 0.
}
}
John
--
The programmer is fighting against the two most
destructive forces in the universe: entropy and
human stupidity. -- Damian Conway
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/