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

NAME
HTML::FormatText - Format HTML as plaintext VERSION
version 2.11 SYNOPSIS
use HTML::TreeBuilder; $tree = HTML::TreeBuilder->new->parse_file("test.html"); use HTML::FormatText; $formatter = HTML::FormatText->new(leftmargin => 0, rightmargin => 50); print $formatter->format($tree); or, more simply: use HTML::FormatText; my $string = HTML::FormatText->format_file( 'test.html', leftmargin => 0, rightmargin => 50 ); DESCRIPTION
HTML::FormatText is a formatter that outputs plain latin1 text. All character attributes (bold/italic/underline) are ignored. Formatting of HTML tables and forms is not implemented. HTML::FormatText is built on HTML::Formatter and documentation for that module applies to this - especially "new" in HTML::Formatter, "format_file" in HTML::Formatter and "format_string" in HTML::Formatter. You might specify the following parameters when constructing the formatter: leftmargin (alias lm) The column of the left margin. The default is 3. rightmargin (alias rm) The column of the right margin. The default is 72. SEE ALSO
HTML::Formatter INSTALLATION
See perlmodinstall for information and options on installing Perl modules. BUGS AND LIMITATIONS
You can make new bug reports, and view existing ones, through the web interface at <http://rt.cpan.org/Public/Dist/Display.html?Name=HTML-Format>. AVAILABILITY
The project homepage is <https://metacpan.org/release/HTML-Format>. The latest version of this module is available from the Comprehensive Perl Archive Network (CPAN). Visit <http://www.perl.com/CPAN/> to find a CPAN site near you, or see <https://metacpan.org/module/HTML::Format/>. AUTHORS
o Nigel Metheringham <nigelm@cpan.org> o Sean M Burke <sburke@cpan.org> o Gisle Aas <gisle@ActiveState.com> COPYRIGHT AND LICENSE
This software is copyright (c) 2013 by Nigel Metheringham, 2002-2005 Sean M Burke, 1999-2002 Gisle Aas. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. perl v5.18.2 2017-10-06 HTML::FormatText(3)
All times are GMT -4. The time now is 11:31 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy