Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Taking information from a text file and inserting it into an html template

by ides (Deacon)
on Dec 13, 2007 at 18:15 UTC ( #656874=note: print w/ replies, xml ) Need Help??


in reply to Taking information from a text file and inserting it into an html template

Hi Bill. All you really need to do is gather up the data from your file into some data structure. If you just need to put the lines as is ( or slightly modified ) an array is probably perfect. If you need to break these lines up into more granular pieces you will probably want an array of hashes with the hashes containing the individual data elements.

Then you can use MIME::Lite::TT::HTML to send your E-mail using a Template Toolkit template. I wrote a short tutorial on how to use this module which can be found here

Once you have the data in some sort of structure, you just pass that data as TmplParams and then can access it in the template for position, loops, etc.

Hope this helps!

Frank Wiles <frank@revsys.com>
www.revsys.com


Comment on Re: Taking information from a text file and inserting it into an html template
Re^2: Taking information from a text file and inserting it into an html template
by wruehl (Acolyte) on Dec 13, 2007 at 19:45 UTC
    Thanks for the reccomendation. This is what I have so far, it is mostly cannibalized from a similar reporting scheme. The comparison tags in here are from the original script, I will not be searching for things like dkcHWProcessor in my script.

    I just need to figure out how to get the line after something is found, IE the line directly after SA220 Fault report, and place it into the array entry. I also need to be able to check that field and compare to "The array is operating normally." in order to flag for the summary.

    use strict; use Time::Local; use File::Basename; use File::Spec; use Cwd; use Getopt::Long; use constant TRUE => 1; use constant FALSE => 0; use MIME::Lite::TT::HTML; use warnings; my $OUTFILE_3 = "/EMC/faults.txt"; my $OUTFILE_5 = "EMCerrors.txt"; my $OUTFILE_6 = "EMCerrorlog.txt"; my $OUTFILE_7 = "EMCmailtxt.txt"; my $OUTFILE_8 = "/EMC/simrc.txt"; # Get the current time and date my @months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); my @weekDays = qw(Sun Mon Tue Wed Thu Fri Sat Sun); my $second = undef; my $minute = undef; my $hour = undef; my $dayOfMonth = undef; my $month = undef; my $yearOffset = undef; my $dayOfWeek = undef; my $dayOfYear = undef; my $daylightSavings = undef; ($second, $minute, $hour, $dayOfMonth, $month, $yearOffset, $dayOfWeek +, $dayOfYear, $daylightSavings) = localtime(); my $year = 1900 + $yearOffset; my $theTime = "$hour:$minute:$second, $weekDays[$dayOfWeek] $months[$m +onth] $dayOfMonth, $year"; my @TEMP_ARRAY_1 = undef; my @TEMP_ARRAY_2 = undef; my @TEMP_ARRAY_3 = undef; my $SRCHSTR = undef; my $SRCHSTR1 = undef; my $SRCHSTR2 = undef; my $SRCHSTR3 = undef; my $PRTSTR = undef; my %PARAMS; open(F_INFILE_3, "< $OUTFILE_3"); open(F_INFILE_8, "< $OUTFILE_8"); $PARAMS{MTIME} = $theTime; foreach (<F_INFILE_3>) { chomp $_; $_ =~ s /^\s//g; $_ =~ s /\./_/g; if ( $_ =~ m/dkcHWProcessor/g ) { @TEMP_ARRAY_1 = split("=",$_); @TEMP_ARRAY_2 = split(":",$TEMP_ARRAY_1[1]); $PARAMS{SA120} = $TEMP_ARRAY_2[1]; if ( $PARAMS{SA120} =~ m/noError/g ) { } else { $PARAMS{SUMMARY} = $PARAMS{SUMMARY}= "SA120;"; } } if ( $_ =~ m/dkcHWCSW/g ) { @TEMP_ARRAY_1 = split("=",$_); @TEMP_ARRAY_2 = split(":",$TEMP_ARRAY_1[1]); $PARAMS{SA121} = $TEMP_ARRAY_2[1]; if ( $PARAMS{SA121} =~ m/noError/g ) { } else { $PARAMS{SUMMARY} = $PARAMS{SUMMARY}= "SA121;"; } } if ( $_ =~ m/dkcHWCache/g ) { @TEMP_ARRAY_1 = split("=",$_); @TEMP_ARRAY_2 = split(":",$TEMP_ARRAY_1[1]); $PARAMS{SA122} = $TEMP_ARRAY_2[1]; if ( $PARAMS{SA122} =~ m/noError/g ) { } else { $PARAMS{SUMMARY} = $PARAMS{SUMMARY}= "SA122;"; } } if ( $_ =~ m/dkcHWSM/g ) { @TEMP_ARRAY_1 = split("=",$_); @TEMP_ARRAY_2 = split(":",$TEMP_ARRAY_1[1]); $PARAMS{SA210} = $TEMP_ARRAY_2[1]; if ( $PARAMS{SA210} =~ m/noError/g ) { } else { $PARAMS{SUMMARY} = $PARAMS{SUMMARY}= "SA220;"; } } if ( $_ =~ m/dkcHWPS/g ) { @TEMP_ARRAY_1 = split("=",$_); @TEMP_ARRAY_2 = split(":",$TEMP_ARRAY_1[1]); $PARAMS{SA211} = $TEMP_ARRAY_2[1]; if ( $PARAMS{SA211} =~ m/noError/g ) { } else { $PARAMS{SUMMARY} = $PARAMS{SUMMARY}= "SA221;"; } } if ( $_ =~ m/dkcHWBattery/g ) { @TEMP_ARRAY_1 = split("=",$_); @TEMP_ARRAY_2 = split(":",$TEMP_ARRAY_1[1]); $PARAMS{SA212} = $TEMP_ARRAY_2[1]; if ( $PARAMS{SA212} =~ m/noError/g ) { } else { $PARAMS{SUMMARY} = $PARAMS{SUMMARY}= "SA222;"; } } } close F_INFILE_3; if ( $PARAMS{SUMMARY} eq "" ) { $PARAMS{SUMMARY} = "NO ERRORS FOUND"; my $msg = MIME::Lite::TT::HTML->new( From => 'santeam@bla.com', To => 'pbkhk@bla.com', Subject => 'EMC CX HEALTH REPORT:NO ERRORS FOUND', Template => { html => 'EMC.html.tt', }, TmplParams => \%PARAMS, ); $msg->send; } else { $PARAMS{SUMMARY} = "ERRORS FOUND:".$PARAMS{SUMMARY}; my $msg = MIME::Lite::TT::HTML->new( From => 'santeam@bla.com', To => 'pbkhk@bla.com', Subject => 'EMC CX HEALTH REPORT:ERRORS FOUND', Template => { html => 'EMC.html.tt', }, TmplParams => \%PARAMS, ); $msg->send; };
    -Bill

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://656874]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (11)
As of 2014-10-01 09:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    What is your favourite meta-syntactic variable name?














    Results (1 votes), past polls