in reply to Re: A CGI whiteboard in Perl
in thread A CGI whiteboard in Perl

in $ENV{REMOTE_USER} =~ m/(m[1|3][[:alpha:]]{3}\d{2})/i do you really mean to match an 'm' followed by one of '1', '|' or '3', or should it be m/(m[13]...?

Generally use statements should go at the top of the file - that is effectively their scope in any case and it makes them easier to find. Strictures should always be on and at the very top of the file of course.

for (my $i = 0; $i <= 3; $i++) {

is more Perlish as:

for my $i (0..3) {
for ($x = 0; $x < 3; $x++) { $rand = rand(255); $hex[$x] = sprintf ("%x", $rand); if ($rand < 9) { $hex[$x] = "0" . $hex[$x]; } if ($rand > 9 && $rand < 16) { $hex[$x] = "0" . $hex[$x]; } } $colors[$i] = "\#" . $hex[0] . $hex[1] . $hex[2]; }

can be replaced by:

$hex[$_] = sprintf "%02x", rand(255) for 0..2;

In fact the whole colour generation loop could be replaced by:

$color[$_] = sprintf "#%02x%02x%02x", rand 255, rand 255, rand 255 for + 0..4;

In general the code would be easier to read with fewer comments. At least use a little vertical white space to make it easier to find sections of code. It's not so bad if you are using a syntax highlighting editor, but otherwise some of the code is simply impossible to see.


DWIM is Perl's answer to Gödel

Replies are listed 'Best First'.
Re^3: A CGI whiteboard in Perl
by OfficeLinebacker (Chaplain) on Nov 08, 2006 at 05:02 UTC
    GP, thanks for your comments, and sorry for the long delay in replying. It looks like the random color thing, while I think it is cool, is not going to fly here. It's still good to learn different ways of coding the functionality. I must admit I still go the for '(my $i=0; $i < $somearbitratyval; $i++)' route. I will strive to work 'for my $i (0..$somearbval)' into future code. That's two dots and not an ellipsis, right?

    _________________________________________________________________________________

    I like computer programming because it's like Legos for the mind.