CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Insert flatline fiels into html table

 



sabercats
Novice

Nov 16, 2012, 3:59 PM

Post #1 of 4 (1659 views)
Insert flatline fiels into html table Can't Post

Hi all,

I have flatfile A.txt 4 fields
Date|Product|Notes|Location so i use myperl.pl to read data as html table as below


Code
#!/usr/bin/perl 

#print "content-type: text/html\n\n";
use warnings;


####################################################################################################


open (DATA,"/mylogs/list.log") || die ("Can't Open data File \n");
@data=<DATA>;
close DATA;
&header_response;
foreach $line (@data) {

$x++;
($date, $product,$notes,$location)=split(/\|/,$line);
{
print "<TD BGCOLOR='F5F5F5'>$date</TD><TD BGCOLOR='F5F5F5'>$product</TD><TD BGCOLOR='F5F5F5'>$note</TD><TD BGCOLOR='F5F5F5'>$location</TD></TR> \n";
}


}


&footer_response;



sub header_response
{
print "Content-type: text/html\n\n";
print "<HTML><HEAD><TITLE>Testing</TITLE>\n";
print "</HEAD>\n";

print "<center><FONT size=+1><TABLE BORDER=3><TR bgcolor=#33FFCC><TD><center><font color=white>Date</center></TD><TD><center><font color=white>Product</center></TD><TD><center><font color=white>Notes</center></TD><TD><center><font color=white>Location</center></TD></TR>\n\n";
return;
}



sub footer_response
{
print "</TABLE></font></CENTER>\n";
print "<BR><BR>\n";
print " </BODY></HTML>\n";
return;
}


Now how you can write it so it will create multiple tables based
on location?

Ex:

Code
<H2>$location</h2> 
<table border="1" bordercolor="#FFCC00" style="background-color:#FFFFCC" width="100%" cellpadding="3" cellspacing="3">
<tr>
<td>Date</td>
<td>Product</td>
<td>Note</td>
</tr>
<tr>
<td>$date</td>
<td>$product</td>
<td>$note</td>
</tr>
</table>


Thanks for your help


wickedxter
User

Nov 16, 2012, 8:03 PM

Post #2 of 4 (1652 views)
Re: [sabercats] Insert flatline fiels into html table [In reply to] Can't Post

you mean keep the different data for the same location?

for that you need a hash to keep track of the locations and when one already exists you can push the data to an Hash of arrays.



Code
 
my $data = {
paris => [[some|info],[more|info]],
japan => [[unk|something],[same|idea]],
};


Then you can build you html table for this data


sabercats
Novice

Nov 18, 2012, 10:01 PM

Post #3 of 4 (1640 views)
Re: [wickedxter] Insert flatline fiels into html table [In reply to] Can't Post

I have list.log

Code
2012/11/13 20:06:11 |t112|norway22|norway  
2012/11/14 14:23:19 |t112|norway10|norway
2012/11/14 15:20:19 |a118|germany10|germany
2012/11/14 16:23:19 |a108|holland10|holland

With my code I will see it like Tables

Code
      Date                        Product    Note            Location 
============== ====== ====== ======
2012/11/13 20:06:11 t112 norway22 norway
2012/11/14 14:23:19 t112 norway10 norway
2012/11/14 15:20:19 a118 germany10 germany
2012/11/14 16:23:19 a108 holland10 holland

I really want it shows like this

Code
                          Location: norway 
Date Product Note
============== ====== ======
2012/11/13 20:06:11 t112 norway22
2012/11/14 14:23:19 t112 norway10

Location: germany
Date Product Note
============== ====== ======
2012/11/14 15:20:19 a118 germany10

Location: holland
Date Product Note
============== ====== ======
2012/11/14 16:23:19 a108 holland10

Thanks


Laurent_R
Veteran / Moderator

Nov 19, 2012, 12:15 AM

Post #4 of 4 (1636 views)
Re: [sabercats] Insert flatline fiels into html table [In reply to] Can't Post

I think the sipplest is to use an hash or arrays, in which the hash key will be the country (e.g. Norway) and the hash value an array of lines (in the xample,
all the lines in which the last field if Norway).

Once you are done reading the log file, you iterate on the key of the hash and just output the libes stored in it.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives