Need help on updating colors in table in perl?

Hello,

I would like your help on this Vector code that creates a matrix..
I need to know how to modfiy this code to do the following -
If Percentages between certain ranges to print colors in the table cell ie <td>.
Ex.  where the parapgraph "p$_/" has these percentages
0.0 - 0.30  - Is a red cell ie #dddcdc
0.30 - 0.60 - Orange
0.60 - 0.80 - Brown
0.80 - 100  - Yellow

Here's the piece of code that I need help with -
# Make a table display

sub mxdisplay {
     my $self = shift;
     my ($i, $j) = (0,0);
     my $matrix = $self->{MATRIX};
     my $vvv = $self->{V};
     my @v = @$vvv;
     my $ret = "";

     $ret = "<table cellpadding=1 cellspacing=1 border=0>\n";
for $i (1..$#v ){
##  my $ii = $i -1;
  my $ii = $i;  # start at p1
  $ret .= "<tr class=bg3 ><td><a href=\"#p$ii\">p$ii</a></td>";
  for $j (1..$#v ){
       $ret .= sprintf("<td>%5.2f</td>",$matrix->{"$i,$j"})
     }
  }
  $ret .= "</tr>\n";
  $ret .= "</table>\n";
  return $ret;
}
To view the running script, you can visit this site-
http://www.textseem.ehost4u.com/webtext-dev/frame1.html/

Awaiting a response,
Thanks!
sdesarAsked:
Who is Participating?
 
ozoConnect With a Mentor Commented:
for $j (1..$#v ){
     my $m = $matrix->{"$i,$j"};
     my $c = qw("red" "orange" "brown" "yellow)[($m>0.3)+($m>0.6)+($m>0.8)];
     $ret .= sprintf("<td><font color=$c>%5.2f</font></td>",$matrix->{"$i,$j"})
}

0
 
sdesarAuthor Commented:
increasing points..
0
 
sdesarAuthor Commented:
I need to know how to modify the code so I can
update the table cell color based on these percentages-
Ex.  where the parapgraph "p$_/" has these percentages
0.0 - 0.30  - Is a red cell ie #dddcdc
0.30 - 0.60 - Orange
0.60 - 0.80 - Brown
0.80 - 100  - Yellow

Eagerly awaiting a response....
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
sdesarAuthor Commented:
Could Ozo please help me??
0
 
sdesarAuthor Commented:
My question is how to modify this piece of code ..
for $j (1..$#v ){
      $ret .= sprintf("<td>%5.2f</td>",$matrix->{"$i,$j"})
    }

.. to do the following -
is matrix (i, j) is between
0.0 - 0.30  - red cell ie #dddcdc ie <td color = red>
0.30 - 0.60 - Orange
0.60 - 0.80 - Brown
0.80 - 100  - Yellow

How can I do this color coding ??

eagerly awaiting a response...

0
 
sdesarAuthor Commented:
Hello Ozo,
Thanks for your suggestion, I have implemented it!

here's the Excellent points!
0
All Courses

From novice to tech pro — start learning today.