Sorry about that, let me see if I can paste a working portion in here

#!/usr/bin/perl use 5.010; use Time::Local; my $file_01_txt = "file_01.txt"; ($sec, $min, $hour, $mday, $mon, $year, $j1,$j2, $j3) =localtime(time) +; $year = $year+1900; $mon = $mon+1; $outfolder = "REPORT_output\_$year\_$mon\_$mday\_\_$hour\_$min\_$sec"; mkdir $outfolder; mkdir "$outfolder/log"; $html_file = <$outfolder/REPORT.html>; $log_file = <$outfolder/log/log.txt>; open($html_report, '>', $html_file) or die "Cannot open file $html_fil +e"; open($log_report, '>', $log_file) or die "Cannot open file $log_file"; main(); sub main { if (-e $file_01_txt) { # We are going to open the log file for appending. open($log_report, '>>', $log_file) or die "Cannot open $log_fi +le."; # We are going to open the HTML file for appending. open($html_report, '>>', $html_file) or die "Cannot open file +$html_file"; # If the file exists, we are going to open it, so we can read +from it. print $log_report "$file_01_txt has been found.\n"; open (my $fh, "<", $file_01_txt) or die "Cannot open file $fil +e_01_txt"; print $html_report "\n"; print $html_report "#### Now Analyzing '$file_01_txt'\n"; print $html_report "\n"; while (my $line = <$fh>) { chomp $line; if ($line =~ /search criteria 01/i) { print $html_report "$line\n"; } if ($line =~ /search criteria 02/i) { print $html_report "$line\n"; } if ($line =~ /search criteria 03/i) { print $html_report "$line\n"; print $html_report "\n"; } } close $log_report; close $html_report; } else { # We are going to open the log file for appending. open($log_report, '>>', $log_file) or die "Cannot open $log_fi +le."; # We are going to log that the file has not been found. print $log_report "$file_01_txt has not been found.\n"; close $log_report; } }

That should work. I just ran it and everything came back as it should.

Please let me know if I need to give you anything else!


In reply to Re^2: Perl File Parsing - My Code Works, but it's Ugly! by Nico
in thread Perl File Parsing - My Code Works, but it's Ugly! by Nico

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.