Solved

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

Posted on 2011-02-21
5
850 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
Comment Utility
How does the @random_color relate $open_color_blue and $close_color_blue?
0
 

Author Comment

by:areyouready344
Comment Utility
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
Comment Utility
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
Comment Utility
Super thanks Wilcoxon for staying up late for this working solution.

Thanks again,
0
 

Author Closing Comment

by:areyouready344
Comment Utility
solution works
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

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…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now