?
Solved

Add a predefined set of colors to the if statement in this Perl code

Posted on 2011-02-21
5
Medium Priority
?
864 Views
Last Modified: 2012-05-11
I need to add a predefined set of colors for a html "font color tag" with the variable name of $open_color with each color looping through the if statement.

Here's the predefined set of colors,

my @random_color= qw(990099 00CC00 CC0066 000033 993300 0000ff 006666);

Here's the full code....

#!/usr/bin/perl

use strict;
use warnings;

open FH, '<', 'a_all.txt' or die $!;

$/='__Data__';

# Html table variables

my $open_table ="<table border=\"1\">";
my $close_table ="</table>";
my $start_row ="<tr>";
my $close_row ="</tr>";
my $open_column_header ="<th>";
my $close_column_header ="</th>";
my $open_column_data ="<td>";
my $close_column_data ="</td>";
my $open_color_blue ="<font color=\"#0000ff\">";
my $close_color_blue ="</font>";
my $blank_row ="<tr><tb></tb><tb></tb></tr>";
my $bold_open ="<b>";
my $bold_close ="</b>";
my @random_color= qw(990099 00CC00 CC0066 000033 993300 0000ff 006666);

# This script creates a html table


print "<html>";
print "<body>";
print $open_table;






   while(<FH>)
       {
            if(/^\@([^\n]*).*((^1\.)(\s*[^\n:]*)([^\n]*))/ms)
            {


           print $start_row,$open_column_data,$open_color_blue,$bold_open,$1,$bold_close,$close_color_blue,$close_column_data,$open_column_data,$3,$open_color_blue,$4,$close_color_blue,$5,$close_column_data,$close_row,"\n";
             #   print $blank_row;
              }


   }

print "</body>";
print "</html>";
0
Comment
Question by:areyouready344
  • 3
  • 2
5 Comments
 
LVL 27

Expert Comment

by:wilcoxon
ID: 34948658
How does the @random_color relate $open_color_blue and $close_color_blue?
0
 

Author Comment

by:areyouready344
ID: 34948719
those are the html font color tags


<font color=\"#0000ff\"> $1 <\font>

$open_color_blue = <font color=\"#0000ff\">
$close_color_blue = <\font>


I want the #0000ff value to change using the color values in the @random_color array variable though each while loop cycle.
I should just drop off the blue variable name and just called it

$open_color_tag
$close_color_tag

thanks for the question...

0
 
LVL 27

Accepted Solution

by:
wilcoxon earned 2000 total points
ID: 34949047
This should do what you want...
#!/usr/bin/perl

use strict;
use warnings;

open FH, '<', 'a_all.txt' or die $!;

$/='__Data__';

# Html table variables

my $open_table ="<table border=\"1\">";
my $close_table ="</table>";
my $start_row ="<tr>";
my $close_row ="</tr>";
my $open_column_header ="<th>";
my $close_column_header ="</th>";
my $open_column_data ="<td>";
my $close_column_data ="</td>";
#my $open_color ="<font color=\"#0000ff\">";
#my $close_color ="</font>";
my $blank_row ="<tr><tb></tb><tb></tb></tr>";
my $bold_open ="<b>";
my $bold_close ="</b>";
my @random_color= qw(990099 00CC00 CC0066 000033 993300 0000ff 006666);
my $color = 4;

# This script creates a html table

print "<html>";
print "<body>";
print $open_table;

while(<FH>)
{
    if(/^\@([^\n]*).*((^1\.)(\s*[^\n:]*)([^\n]*))/ms)
    {
        $color++;
        $color = 0 if ($color >= @random_color);
        print $start_row,$open_column_data,
            "<font color=\"$random_color[$color]\">",$bold_open,$1,$bold_close,"</font>",
            $close_column_data,$open_column_data,$3,
            "<font color=\"$random_color[$color]\">",$4,"</font>",
            $5,$close_column_data,$close_row,"\n";
        #   print $blank_row;
    }
}

Open in new window

0
 

Author Comment

by:areyouready344
ID: 34949387
Super thanks Wilcoxon for staying up late for this working solution.

Thanks again,
0
 

Author Closing Comment

by:areyouready344
ID: 34949391
solution works
0

Featured Post

Technology Partners: 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!

Question has a verified solution.

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

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
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
Suggested Courses

809 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