Welcome to WebmasterWorld Guest from 54.234.129.215

Forum Moderators: coopster & jatar k & phranque

Message Too Old, No Replies

Toggles in Perl (or other langs)

     

Brett_Tabke

4:20 pm on Feb 11, 2001 (gmt 0)

WebmasterWorld Administrator brett_tabke is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



I use this 4 liner alot to flip between colors in generated tables (used on home page and within thread displays here):

$bg++;
$bg=0 if $bg > 1;
$bgcolor ="fafafa";
$bgcolor ="ffffff" if $bg;

Example <tr bgcolor="#$bgcolor">

Got a quicker way to to the 4 lines?

littleman

4:54 pm on Feb 11, 2001 (gmt 0)

WebmasterWorld Senior Member littleman is a WebmasterWorld Top Contributor of All Time 10+ Year Member



I don't know if it is shorter but I've been doing this approach.

$bg =1;
--
if ($bg) {$bgcolor ="fafafa"; $bg=0;}
else {$bgcolor ="ffffff"; $bg=1;}

sugarkane

5:12 pm on Feb 11, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



How about this?

$bgcolor="ffffff";
$bgcolor2="fafafa";

($bgcolor, $bgcolor2) = ($bgcolor2, $bgcolor);

Use the 3rd line in your loop to toggle between the 2 values

Air

7:05 pm on Feb 11, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



push (@bgcolor, "ffffff" , "fafafa");
print "<tr bgcolor=#$bgcolor[$bg++]>\n";

Brett_Tabke

8:25 am on Feb 12, 2001 (gmt 0)

WebmasterWorld Administrator brett_tabke is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



That's slick Air, but memory inefficient and I'd bet the push is quite a bit slower than a pure declaration.

That is also slick SK.

 

Featured Threads

Hot Threads This Week

Hot Threads This Month