RE: Changing row color with subroutine - a shortcut...

2002-11-22 Thread dirk van der Giesen
I rememeber sometimes doing something like this when
using CGI.pm and DBI.pm


push(@rows,td({-colspan=>'6',-bgcolor=>'#FF'},[$th]));

#blank row

$th = ' ';

push(@rows,td({-colspan=>'6',-bgcolor=>'#FF'},[$th]));

push(@rows,td({-bgcolor=>'#FFCC99'},['',b('Verwijderen:'),b('Naam:'),b('Voornaam:'),b('Vertegenwoordiger:*'),b('Bekijk
CV:')]));
while (@data = $cursor->fetchrow) {
$count++;
if ($count % 2 == 0){
$bgcolor = "#FFCC99";
}else{
$bgcolor = "#FF";
}

etc..

and then i the end i printed the table

$innertable = table({-border=>'0',-width=>'100%',
-cellspacing=>'1', -cellpadding=>'2',
-bgcolor=>'#FF'},Tr(\@rows));


I always founded this a very nice feature of CGI.pm.

The only thing i never found out is how you could
manipulate tables in this same kind of way ? 


Thanks,

Dirk



--- Peter Kappus <[EMAIL PROTECTED]> wrote:
> Another neat trick I use to get subroutine arguments
> is the old "shift"
> function without an argument.
> 
> Since, @_ is the default array in a subroutine you
> can just say
> 
> my $firstParm = shift; #shift off the first arg from
> @_
> 
> 
> Therefore, 
> 
> print add(30,50);
> 
> sub addTwo{
>   my $firstNum = shift;
>   my $secondNum = shift;
>   return $firstNum + $secondNum;
> }
> 
> will print "80".  neato eh?
> 
> another fun trick if you have, say, 3 arguments is
> to say
> 
> my ($name, $size, $color) = @_;
> 
> this will map the first three args in your args
> array two the variables
> $name, $size, and $color.
> 
> I hope this is useful...
> 
> -PK
> 
> -Original Message-
> From: zentara [mailto:[EMAIL PROTECTED]]
> Sent: Friday, November 22, 2002 6:33 AM
> To: [EMAIL PROTECTED]
> Subject: Re: Changing row color with subroutine
> 
> 
> On Fri, 22 Nov 2002 03:28:39 -0800,
> [EMAIL PROTECTED] (Poster) wrote:
> 
> >Hi, I am having a little trouble with a sub that is
> using the modulus
> >operator.
> 
> Yeah, it fooled me too for a bit :-)
> The problem is the way you pass the value to the
> sub, @_ always is 1, the count of elements in @_.
> Change @_ to @_[0]  or better yet $_[0]
> 
> >--here is the sub
> >sub color_rows
> >{
> >my $num = @_;
> 
> 
> -- 
> To unsubscribe, e-mail:
> [EMAIL PROTECTED]
> For additional commands, e-mail:
> [EMAIL PROTECTED]
> 


__
Do you Yahoo!?
Yahoo! Mail Plus – Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Changing row color with subroutine - a shortcut...

2002-11-22 Thread Peter Kappus
Another neat trick I use to get subroutine arguments is the old "shift"
function without an argument.

Since, @_ is the default array in a subroutine you can just say

my $firstParm = shift; #shift off the first arg from @_


Therefore, 

print add(30,50);

sub addTwo{
my $firstNum = shift;
my $secondNum = shift;
return $firstNum + $secondNum;
}

will print "80".  neato eh?

another fun trick if you have, say, 3 arguments is to say

my ($name, $size, $color) = @_;

this will map the first three args in your args array two the variables
$name, $size, and $color.

I hope this is useful...

-PK

-Original Message-
From: zentara [mailto:[EMAIL PROTECTED]]
Sent: Friday, November 22, 2002 6:33 AM
To: [EMAIL PROTECTED]
Subject: Re: Changing row color with subroutine


On Fri, 22 Nov 2002 03:28:39 -0800, [EMAIL PROTECTED] (Poster) wrote:

>Hi, I am having a little trouble with a sub that is using the modulus
>operator.

Yeah, it fooled me too for a bit :-)
The problem is the way you pass the value to the
sub, @_ always is 1, the count of elements in @_.
Change @_ to @_[0]  or better yet $_[0]

>--here is the sub
>sub color_rows
>{
>my $num = @_;


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Changing row color with subroutine

2002-11-22 Thread zentara
On Fri, 22 Nov 2002 03:28:39 -0800, [EMAIL PROTECTED] (Poster) wrote:

>Hi, I am having a little trouble with a sub that is using the modulus
>operator.

Yeah, it fooled me too for a bit :-)
The problem is the way you pass the value to the
sub, @_ always is 1, the count of elements in @_.
Change @_ to @_[0]  or better yet $_[0]

>
>It is called here-within a while loop:
>while (my $row = $sth->fetchrow_hashref()) {
>   count++;
>   color_rows( $count )
>   --some other stuff
>   table cell value
>   -some other stuff
>}
>--here is the sub
>sub color_rows
>{
>my $num = @_;

my $num = $_[0];

>my $bgcolor;
>
>If ( $num % 2 == 0 ) {
>   $bgcolor="#bde6de";
>} else {
>   $bgcolor="white";
>}
>return $bgcolor;
>}#end sub
>
>I expect that when the value that is passed in $count is even it will
>set the row color green, otherwise it will set it to white. What it is
>actually doing is setting the value white every time. 
>
>Thanks.
>
>Ramon Hildreth
>---
>[ www.subudusa.org ] [ www.subudseattle.org ]
>[ www.ramonred.com ]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Changing row color with subroutine

2002-11-22 Thread Poster
Hi, I am having a little trouble with a sub that is using the modulus
operator.

It is called here-within a while loop:
while (my $row = $sth->fetchrow_hashref()) {
count++;
color_rows( $count )
--some other stuff
table cell value
-some other stuff
}
--here is the sub
sub color_rows
{
my $num = @_;
my $bgcolor;

If ( $num % 2 == 0 ) {
$bgcolor="#bde6de";
} else {
$bgcolor="white";
}
return $bgcolor;
}#end sub

I expect that when the value that is passed in $count is even it will
set the row color green, otherwise it will set it to white. What it is
actually doing is setting the value white every time. 

Thanks.

Ramon Hildreth
---
[ www.subudusa.org ] [ www.subudseattle.org ]
[ www.ramonred.com ]