?
Solved

Need help on updating colors in  table in perl?

Posted on 2003-03-12
6
Medium Priority
?
187 Views
Last Modified: 2010-03-05
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!
0
Comment
Question by:sdesar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
6 Comments
 

Author Comment

by:sdesar
ID: 8144746
increasing points..
0
 

Author Comment

by:sdesar
ID: 8145276
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
 

Author Comment

by:sdesar
ID: 8148335
Could Ozo please help me??
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:sdesar
ID: 8148508
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
 
LVL 84

Accepted Solution

by:
ozo earned 400 total points
ID: 8148679
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
 

Author Comment

by:sdesar
ID: 8156700
Hello Ozo,
Thanks for your suggestion, I have implemented it!

here's the Excellent points!
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question