On Nov 22, Poster said:
>Hi, I am having a little trouble with a sub that is using the modulus
>operator.
No, your function is written incorrectly, and you don't use it correctly.
>while (my $row = $sth->fetchrow_hashref()) {
> count++;
> color_rows( $count )
> ------some other stuff
> <td bgcolor="$bgcolor">table cell value</td>
> -----some other stuff
>}
>sub color_rows {
>my $num = @_;
First mistake is that line. That assigns the NUMBER of elements in @_ to
$num. Use one of the following methods:
my $num = shift;
# or
my ($num) = @_;
>my $bgcolor;
Your while loop can't see this variable.
>if ( $num % 2 == 0 ) {
> $bgcolor="#bde6de";
>} else {
> $bgcolor="white";
>}
>return $bgcolor;
>}#end sub
If you're returning a value, USE it:
while (...) {
my $bg = color_rows($count++);
print qq{<td bgcolor="$bg">...</td>};
}
There's no need for a function, though.
while (...) {
my $bg = $count++ % 2 ? "#bde6de" : "#ffffff";
# ...
}
--
Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/
RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/
<stu> what does y/// stand for? <tenderpuss> why, yansliterate of course.
[ I'm looking for programming work. If you like my work, let me know. ]
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]