Writing an HTML file in perl

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Writing an HTML file in perl
# 1  
Old 05-24-2013
Writing an HTML file in perl

I'm writing a perl script that writes an html file.
use Tie::File;

my ($dir) = @ARGV;

open (HTML,">","$dir/file.html") || die $!;

#-----Building HTML file---------------------------
print HTML "<!DOCTYPE html>
		<link href=\"styles/styles.css\" type=\"text/css\" rel=\"stylesheet\" />  
   <body> ";

my $TABLE = "/data_table_location/TABLE";

my @TABLE;
tie @TABLE, 'Tie::File', $TABLE or die;

foreach (@TABLE)

if (($_ =~/^\w\w\w\d\d\-/) || ($_ =~/^Data/) || ($_=~/^$/)){

	if ($_ =~/^\w\w\w\d\d\-/){print HTML "<h3>$_</h3>";}
	if ($_ =~/^Data/){print HTML "<pre><b>	Data		Pos	Ref	Cov	Deletions</b></pre>";}
	if ($_=~/^$/) {print HTML "";}

my @line = split (/\t/,$_);

my $position = $line[1];
my $reference = $line[2];
my $coverage = $line[3];
my $Deletions = $line[4];

print HTML "<pre>	$position	$reference	$coverage	$Deletions	</pre>";

print HTML "

close (HTML);

The output should be a table like this.

ABC12 #title of data set
Data Pos Ref Cov Deletetions #types of data
0 1 2 3

My issue is in my css which I have not done too much with because I cannot get it to work.

h3 {
	text-align: center;
	color: Blue;}

This script is called by another script, using the data from that script to build the table, and output the table. The issue I am having is that the newly created HTML file is ignoring aspects of my css style sheet. If I set the...
	background-color: Red;}

...the background color changes to red. But I cannot change the header, it will not center the font or change the color to blue. The most progress I've made is making the HTML even recognize that that IS a header, and thus making the font larger and bolding it. But nothing I do to the header works. I need to make changes to the header, and also once that gets sorted out the table itself will be in <div> tags.

Why doesn't the header format as directed too? Is it because the header itself is an iterator or because the HTML is being created as the script runs and thus the css doesn't load the styles for items that are not yet written?

My ultimate goal is to have the perl script output a formatted html file.

Thank you for your time.
# 2  
Old 05-24-2013
Not so big on css, but if you put data into html, you must scrub all <>"'& to: &lt; &gt; &quot; &apos; &amp; And do & first. Now, I think perl has calls to do this, so if you used them, my apologies.

Tables: Decide to use <TABLE> or <PRE>, not both. Since <PRE> is fixed pitch, you can make nice columns with padding, but no borders and shading. I have had great success with <PRE> tables for bulk data presentation, as it is cheap on the browser side typesetting, whereas <TABLE> needs to typeset everything before it can set column widths.

Can you show us an output document?

Last edited by DGPickett; 05-28-2013 at 06:37 PM..
# 3  
Old 05-24-2013
I wrote an html script, only html, to produce the output I want, and am now implementing parts of that code into my perl script. The first image is what my output will hopefully look like after everything is said and done. The second image is what happens when you click on the header, the data unfolds for ease of viewing. The third image is what my output looks like now.

The first two images are from a solely html script.
The third image is from my perl script that writes the html. As you can see, the header is bolded and enlarged, as should be since I have the <h3> tags on it. But nothing else is being used from my css. Granted, in this example, my css is very bare bones since I cannot even get the header to move to the center of the screen, I did not bog it down with code I knew would not work.
Writing an HTML file in perl-doldedpng
Writing an HTML file in perl-dropdownpng
Writing an HTML file in perl-untitledpng
# 4  
Old 05-28-2013
Well, make it simpler and simpler, to see where it falls off the rails. First get a table to behave, and then work on the color and font.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Input data of a file from perl into HTML table

Hi , I need an help in perl scripting. I have an perl script written and i have an for loop in that ,where as it writes some data to a file and it has details like below. cat out.txt This is the first line this is the second line. .....Now, this file needs to be send in mail in HTML... (2 Replies)
Discussion started by: scott_cog
2 Replies

2. Shell Programming and Scripting

Perl: Writing table values to a file

I have a file like this, 1,a,saurav 2,b,rout I want to show this file in a perl cgi page table and want to add a column which will contain a text box. There I will give some manual input, which will be written to the existing file(or a new file) in below format. 1|a|saurav|bangalore... (2 Replies)
Discussion started by: sauravrout
2 Replies

3. Shell Programming and Scripting

Editing path in a HTML file using Perl

Hello I want to replace the path to which a hyperlink points to. I have a html file <TABLE BORDER CELLPADDING=7, border=0><TR><td>Jun-10-2013_03_19_07_AM</td><td>Ank_Insert_1</td><td><b>FAILED: 1</b></td><td><A ... (14 Replies)
Discussion started by: ankurk
14 Replies

4. Shell Programming and Scripting

Perl script for Calling a function and writing all its contents to a file

I have a function which does awk proceessing sub mergeDescription { system (q@awk -F'~' ' NR == FNR { A = $1 B = $2 C = $0 next } { n = split ( C, V, "~" ) if... (3 Replies)
Discussion started by: crypto87
3 Replies

5. Shell Programming and Scripting

Writing HTML with variables from an array or other means

Hello! I wish to create a script that will automate the creation of HTML files... for example, if my HTML starts out containing: <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>$TITLE</title> </head> I want to put that into something that I can read and write later on. My... (4 Replies)
Discussion started by: tntelle
4 Replies

6. Shell Programming and Scripting

editing single line in html file in perl script

Hi Folks, It is regarding the perl scripting. I have an html file(many files) which contains the below line in the body tag. <body> <P><STRONG><FONT face="comic sans ms,cursive,sans-serif"><EM>Hello</EM></FONT></STRONG></P> </body> Now I want to read that html file through perl... (3 Replies)
Discussion started by: giridhar276
3 Replies

7. Shell Programming and Scripting

Writing html to a file with echo

Hi, I'm having an issue with echo again. I keep getting errors and no file content with these commands in a script. --------------------------------------------------- #!/bin/bash WEBSITE=http://www.google.com touch test1.txt echo "replace("<body>","<body><iframe... (2 Replies)
Discussion started by: digitalviking
2 Replies

8. Shell Programming and Scripting

Is it possible to convert text file to html table using perl

Hi, I have a text file say file1 having data like ABC c:/hm/new1 Dir DEF d:/ner/d sd ...... So i want to make a table from this text file, is it possible to do it using perl. Thanks in advance Sarbjit (1 Reply)
Discussion started by: sarbjit
1 Replies

9. Shell Programming and Scripting

how to display the output file in an html format using perl

Hi, I have written a perl script to dispaly some statements from a file but i want the output statements to be dispalyed in an HTML format.Is it possible for me to do in perl scripting? Please help me with ur thoughts. Thanks In Advance Meva. (1 Reply)
Discussion started by: meva
1 Replies

10. Shell Programming and Scripting

help for a perl script - writing to a data file

Hi, Here is my problem.. i have 2 files (file1, file2).. i have wrote the last two lines and first 4 lines of "file2" into two different variables .. say.. my $firstrec = `head -4 $file2`; my $lastrec = `tail -2 $file2`; and i write the rest of the file2 to a tmpfile and cat it with head... (2 Replies)
Discussion started by: meghana
2 Replies
Login or Register to Ask a Question

Featured Tech Videos