in reply to Re^2: split the text file to multiple arrays
in thread split the text file to multiple arrays
Your code does not compile
Missing right curly or square bracket at 1194338.pl line 100, at end of line syntax error at 1194338.pl line 100, at EOF 1194338.pl had compilation errors.
Try
poj#!/usr/bin/perl use strict; use warnings; use Time::Piece; # current date/time my $t = localtime; my $date = $t->wdayname.' '.$t->dmy('/'); my $time = $t->hms; # input data my $dest = "C:/Perl-Script/"; my %hdata = build_hash($dest."Bulletin.txt"); # output html open OUT, ">". $dest."Bulletin.html" or die "$!"; print OUT qq( <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title>My Learning Page</title> <style type="text/css"> body { background-color: #ccccff; } h2 { color: #0; font-size: 2em; } th { background-color: #e0e0e0 } td { background-color: #ffffff } </style> </head> <body> <h2>My Home Page</h2> <h2>Bulletin Date $date $time</h2>\n); foreach my $key (sort keys %hdata) { if (($key eq '"$Persons Absences?"') || ($key eq '"$Replacement Persons?"') || ($key eq '"$Room Changes?"')){ print OUT qq!<h3>$key</h3> <table border="1" width="100%" style="border-color:#e0e0e0" cellpa +dding="5" align="left">\n!; my @arrays = @{$hdata{$key}}; for my $i (1..$#arrays) { print OUT '<tr>'; my @col = split(/,/,$arrays[$i]); for my $j (1..$#col) { $col[$j] =~ s/"//g; my $td = ($i==1)? "th" : "td"; print OUT qq!<$td align="left">$col[$j]</$td>!; }; print OUT "</tr>\n"; }; print OUT "</table> <br>\n"; }; } print OUT "</body></html>"; close OUT; #------------------------------------- # This subroutine split text file to # number of arrays for data processing # ------------------------------------- sub build_hash{ my $infile = shift; my %data; my $last =''; open my $ifh,'<',$infile or die "$!"; while (my $line=<$ifh>) { chomp $line; if ( substr($line,0,2) eq '"$' || substr($line,0,1) eq '$') { $last = $line; } push @{$data{$last}},$line; } close $ifh; return %data; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: split the text file to multiple arrays
by mhoang (Acolyte) on Jul 07, 2017 at 00:23 UTC | |
by huck (Prior) on Jul 07, 2017 at 01:02 UTC | |
by mhoang (Acolyte) on Jul 11, 2017 at 05:37 UTC | |
by huck (Prior) on Jul 11, 2017 at 05:43 UTC | |
by mhoang (Acolyte) on Jul 14, 2017 at 04:03 UTC | |
|