Perl match odd numbers (or even)

Shearer-Services
Shearer-Services used Ask the Experts™
on
I am trying to find a more extensible way to use different CSS classes in a table depending whether the row is an even or odd road.  Currently, I have the following:

if ($flag =~ m/1|3|5|7|9|11|13|15|17|19|21|23|25|27|29|31/) }
   print "<tr class="odd">;
else {
   print "<tr class="even">;
}

Kinda what I am thinking would be something like this:

if ($flag =~ m/:[IsOdd}:) }
   print "<tr class="odd">;
else {
   print "<tr class="even">;
}

Thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
There is no need of any regular expression. You can handle it by a simple logic

$flag = 5;

for($i=0;$i<$flag;$i++)
{
        if($i % 2 == 1)
        {
                print "<tr class=odd>";
        }
        else
        {
                print "<tr class=even>";
        }
}

Gourav Jain
Webdunia
why not try this

if ($flag =~ /[13579]$/)
{
print "<tr class="odd">;
else {
  print "<tr class="even">;
}

thanks
-manas

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial