homepage Welcome to WebmasterWorld Guest from 54.242.126.126
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
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

WebmasterWorld Administrator brett_tabke us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 217 posted 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

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



 
Msg#: 217 posted 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

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 217 posted 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

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 217 posted 7:05 pm on Feb 11, 2001 (gmt 0)

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

Brett_Tabke

WebmasterWorld Administrator brett_tabke us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 217 posted 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.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved