Solved

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

Posted on 2011-02-21
5
858 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
[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
  • 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

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.

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…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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…

726 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