|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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? |
|
#2
|
|||
|
|||
|
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 |
|
#3
|
|||
|
|||
|
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).] |
|
#4
|
|||
|
|||
|
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 |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > Odd and Even numbers |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|