#!/usr/bin/perl use strict; use warnings; use autodie; use List::Util 'any'; use Text::CSV; my $input_file = 'DATA.csv'; my (@headers, %docs); my $n = 0; my @docs; open my $fh, '>',"fh.html"; open(my $Fhresult, '<', $input_file); while (<$Fhresult> ) { last if (/^\d+\s+\d{2}:\d{2}:\d{2}\s*$/); } while (<$Fhresult> ) { if ($. == 2) { chomp; s/^default,\s*//; @headers = split ( /[ ,. ;:\(\)\/\*\"]+/ ); next; } next unless /\S/; chomp; my ($file, @fields) = split /\s*,\s*|\s+/; push @docs, {'file'=>$file, 'fields'=>\@fields} if any { $_ eq 'fault' } @fields; } close($Fhresult); foreach my $doc (@docs) { open($fh, '>', "$doc->{'file'}.html" ); print $fh " SYSTEM \n
\n\n\n\n\n"; foreach (0..$#headers) { print $fh ("\n"); ++$n; } print $fh "\n
"; print $fh $doc->{'file'} , ":
$headers[$_]$doc->{'fields'}[$_]
\n"; } my $csv = Text::CSV->new; open my $csv_file, "<", "DATA2.csv" or die "Can't open CSV file: $!\n"; while (my $row = $csv->getline($csv_file)) { my($significator_and_file) = clean($row->[0]); my ($significator, $file) = split /\s+/, $significator_and_file; next unless $significator and $significator eq 'false'; open (my $per_line_fh, ">>", "$file.html") or die "Can't open per-line file $file: $!\n"; shift @$row; print $per_line_fh "\n\n"; for my $i(map {clean($_)} @$row) { #chomp $i; my $d = "\n"; chomp $i; print $per_line_fh $d if ($i); } print $per_line_fh "
$file:
$i
\n\n"; close $per_line_fh; } sub clean { my $string = shift; $string =~ /\s*,\s*/; $string =~ /\s*,\s*/; return $string; }