homepage Welcome to WebmasterWorld Guest from 107.20.131.154
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld
Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
Forum Library, Charter, Moderators: coopster & jatar k & phranque

Perl Server Side CGI Scripting Forum

    
Toggles in Perl (or other langs)
Brett_Tabke




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

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




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

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




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

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




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

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

Brett_Tabke




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

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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved