Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old September 25th, 2000, 03:59 AM
tpe tpe is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2000
Location: Greece
Posts: 10 tpe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 m 38 sec
Reputation Power: 0
Hallo,
I want to create a Perl script that will read a few lines from a database and then it will create an HTML table. The problem:
I need a function that will finds if a number is odd or even because I want to have defferent color to each line. Does anybody knows how to do that?

Reply With Quote
  #2  
Old September 25th, 2000, 06:35 AM
MeijdenB MeijdenB is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2000
Location: Alkmaar, The Netherlands
Posts: 123 MeijdenB User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
Use modula(%)-operator. If x%2 is 1 then odd . If x%2 is 0 then even. In Perl:

if ($number%2==1) {
# $number is odd
}
else {
# $number is even
}

------------------
Good luck,
Bas

------------------
E-mail me at: b.vandermeijden@pecoma.nl

Reply With Quote
  #3  
Old September 25th, 2000, 09:43 PM
billyo billyo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Posts: 114 billyo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
I think you could do this in PERL, but this is PHP, i think it's a little cleaner than using an if-then construct.

$rowColors=Array("#cccccc","#eeeeee");
/*
I think the PERL would be something like:
@rowColor=("#cccccc","#eeeeee");
and then you use "print" and not echo,
right?
*/
$index=0;
echo "<table>";
for ($i=0;$i<10;$i++)
{
echo "<tr bgcolor=".$rowColors[$index]."><td></td></tr>";
$index=-($index)+1; // this makes it alternate
}
echo "</table>";

Hope that helps.

[This message has been edited by billyo (edited September 25, 2000).]

Reply With Quote
  #4  
Old September 26th, 2000, 04:38 AM
tpe tpe is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2000
Location: Greece
Posts: 10 tpe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 m 38 sec
Reputation Power: 0
Hi again.
THe second message looked more like perl (or C++ ). I tries both solutions. I was thinking that the % was PHP too, but it worked fine.
So, I have to say thanks.
Cheers,
Peter

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Odd and Even numbers


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway