areyouready344
asked on
Convert records into html table using Perl
I have the following data record in a scsi_test file that I would like to convert into a html table using perl
Here's the data record....
__Data__
scsi_test_hotswap
stop
Passed
1. dldldld - dldldldldldldldld
2. dldldld - dldldldldlldldldld
1. dldldld - dldldldldldldldld
2. dldldld - dldldldldlldldldld
__Data__
scsi_test_memory_leakage
stop
Passed
1. dldldld - dldldldldldldldld
2. dldldld - dldldldldlldldldld
3. dldldld - dldldldldldldldld
4. dldldld - dldldldldlldldldld
__Data__
scsi_test_scatter_gatter
Starting Code...
--------------------
#!/usr/bin/perl
use warnings;
use strict;
# Html table tag variables
my $open_table ="<table border=\"1\">";
my $close_table ="</table>";
my $open_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_column ="<tr></tr>";
my @first_record_row; # this should include the first element and element starting with 1. from the whole_record array
excluding the __Data__ input record separator.
my @additional_record_rows; # this should include the remaining elements in the whole_record array.
# Input Record Separator
$/='__Data__';
# Read In file
open FH,'<',"scsi_test" or die $!;
while(<FH>)
{
s/^\s+//;
s/^\s+$//;
print "@whole_record","\n";
foreach (@whole_record)
{
print $whole_record[1],"\n";
# push @first_record_row = grep(m/^1\..*/,@whole_reco rd);
# print @first_record_row;
}
Output should look like this....
row_1 -----> scsi_test_hotswap Passed 1. dldldld - dldldldldldldldld
row_2 -----> 2. dldldld - dldldldldldldldld
row_3 -----> 3. dldldld - dldldldldldldldld
row_4 -----> 4. dldldld - dldldldldldldldld
row_5 -----> blank line row
row_6 -----> scsi_test_memory_leakage Passed 1. dldldld - dldldldldldldldld
row_7 -----> 2. dldldld - dldldldldldldldld
row_8 -----> 3. dldldld - dldldldldldldldld
Side note, the text upto the hypen should be color blue blod as in, dldldld -, and excluding the line number.
Here's the data record....
__Data__
scsi_test_hotswap
stop
Passed
1. dldldld - dldldldldldldldld
2. dldldld - dldldldldlldldldld
1. dldldld - dldldldldldldldld
2. dldldld - dldldldldlldldldld
__Data__
scsi_test_memory_leakage
stop
Passed
1. dldldld - dldldldldldldldld
2. dldldld - dldldldldlldldldld
3. dldldld - dldldldldldldldld
4. dldldld - dldldldldlldldldld
__Data__
scsi_test_scatter_gatter
Starting Code...
--------------------
#!/usr/bin/perl
use warnings;
use strict;
# Html table tag variables
my $open_table ="<table border=\"1\">";
my $close_table ="</table>";
my $open_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_column ="<tr></tr>";
my @first_record_row; # this should include the first element and element starting with 1. from the whole_record array
excluding the __Data__ input record separator.
my @additional_record_rows; # this should include the remaining elements in the whole_record array.
# Input Record Separator
$/='__Data__';
# Read In file
open FH,'<',"scsi_test" or die $!;
while(<FH>)
{
s/^\s+//;
s/^\s+$//;
print "@whole_record","\n";
foreach (@whole_record)
{
print $whole_record[1],"\n";
# push @first_record_row = grep(m/^1\..*/,@whole_reco
# print @first_record_row;
}
Output should look like this....
row_1 -----> scsi_test_hotswap Passed 1. dldldld - dldldldldldldldld
row_2 -----> 2. dldldld - dldldldldldldldld
row_3 -----> 3. dldldld - dldldldldldldldld
row_4 -----> 4. dldldld - dldldldldldldldld
row_5 -----> blank line row
row_6 -----> scsi_test_memory_leakage Passed 1. dldldld - dldldldldldldldld
row_7 -----> 2. dldldld - dldldldldldldldld
row_8 -----> 3. dldldld - dldldldldldldldld
Side note, the text upto the hypen should be color blue blod as in, dldldld -, and excluding the line number.
ASKER
thanks but did not work, got the output of
<table border="1"><table border="1">
I'll try it again later
<table border="1"><table border="1">
I'll try it again later
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
excellent answer
To make it easier to test I changed it so it takes input from stdin, so run it like this:
perl makeTab.pl scsi.test >scsiTest.html
Open in new window