in reply to Error while taking 'Scalar of scalar'
have you ever wondered why you only get back the first two colors? rand(x) returns a random number between 0 and (excluding) x.my @color= qw( lavender lightblue honeydew); my $color_no=int(rand($#color)); return $color[$color_no];
the usual idiom for this in perl is:
my @colors = qw(lavender lightblue honeydew); my $color = $colors[rand @colors]; return $color;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Error while taking 'Scalar of scalar'
by bart (Canon) on Jul 05, 2007 at 12:39 UTC |