Solved

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

Posted on 2011-02-21
5
855 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 26

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 26

Accepted Solution

by:
wilcoxon earned 500 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Perl strange behaviour 5 71
Perl Sort Question 4 133
Replace  text in a file 2 104
Is it true to say that Python is successor of Perl? 7 173
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

806 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