Sponsored Content
Full Discussion: Writing an HTML file in perl
Top Forums UNIX for Dummies Questions & Answers Writing an HTML file in perl Post 302811907 by jrymer on Friday 24th of May 2013 01:59:18 PM
Old 05-24-2013
Writing an HTML file in perl

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

my ($dir) = @ARGV;

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

#-----Building HTML file---------------------------
print HTML "<!DOCTYPE html>
<html>
	<head>
	<title>Output</title>
		<link href=\"styles/styles.css\" type=\"text/css\" rel=\"stylesheet\" />  
		
	</head>
   <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 "";}
	
}
else{

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 "
</body>
</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.

Code:
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...
Code:
body{ 
	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.
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
HTML::Filter(3) 					User Contributed Perl Documentation					   HTML::Filter(3)

NAME
HTML::Filter - Filter HTML text through the parser NOTE
This module is deprecated. "HTML::Parser" now provides the functionally of "HTML::Filter" much more efficiently with the the "default" han- dler. SYNOPSIS
require HTML::Filter; $p = HTML::Filter->new->parse_file("index.html"); DESCRIPTION
"HTML::Filter" is an HTML parser that by default prints the original text of each HTML element (a slow version of cat(1) basically). The callback methods may be overridden to modify the filtering for some HTML elements and you can override output() method which is called to print the HTML text. "HTML::Filter" is a subclass of "HTML::Parser". This means that the document should be given to the parser by calling the $p->parse() or $p->parse_file() methods. EXAMPLES
The first example is a filter that will remove all comments from an HTML file. This is achieved by simply overriding the comment method to do nothing. package CommentStripper; require HTML::Filter; @ISA=qw(HTML::Filter); sub comment { } # ignore comments The second example shows a filter that will remove any <TABLE>s found in the HTML file. We specialize the start() and end() methods to count table tags and then make output not happen when inside a table. package TableStripper; require HTML::Filter; @ISA=qw(HTML::Filter); sub start { my $self = shift; $self->{table_seen}++ if $_[0] eq "table"; $self->SUPER::start(@_); } sub end { my $self = shift; $self->SUPER::end(@_); $self->{table_seen}-- if $_[0] eq "table"; } sub output { my $self = shift; unless ($self->{table_seen}) { $self->SUPER::output(@_); } } If you want to collect the parsed text internally you might want to do something like this: package FilterIntoString; require HTML::Filter; @ISA=qw(HTML::Filter); sub output { push(@{$_[0]->{fhtml}}, $_[1]) } sub filtered_html { join("", @{$_[0]->{fhtml}}) } SEE ALSO
HTML::Parser COPYRIGHT
Copyright 1997-1999 Gisle Aas. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.8.0 1999-12-09 HTML::Filter(3)
All times are GMT -4. The time now is 08:26 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy