Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: How to convert a text file to a HTML file

by choroba (Abbot)
on Jan 25, 2013 at 12:03 UTC ( #1015332=note: print w/ replies, xml ) Need Help??


in reply to How to convert a text file to a HTML file

Just add the header and footer:

#!/usr/bin/perl use strict; use warnings; open my $HTML, '>', 'output.html' or die $!; print $HTML <<'_END_HEADER_'; <html> <head><title></title></head> <body> _END_HEADER_ open my $IN, '<', 'input.txt' or die $!; while (my $line = <$IN>) { # You probably want to do more work here. print $HTML $line; } print $HTML '</body></html>'; close $HTML or die $!;
لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ


Comment on Re: How to convert a text file to a HTML file
Download Code
Re^2: How to convert a text file to a HTML file
by Utilitarian (Vicar) on Jan 25, 2013 at 12:20 UTC
    Meh, why do any work ;)
    #!/usr/bin/perl use strict; use warnings; open my $HTML, '>', 'output.html' or die $!; print $HTML <<'_END_HEADER_'; <html> <head><title></title></head> <body> <pre> _END_HEADER_ open my $IN, '<', 'input.txt' or die $!; print $HTML while <$IN>; print $HTML '</pre></body></html>'; close $HTML or die $!;
    print "Good ",qw(night morning afternoon evening)[(localtime)[2]/6]," fellow monks."

      Hi

      Thanks for your input. Now let me re-iterate my problem this way. Suppose I have simple a.txt(pasted below) file in my desktop. When I open that file on the browser by giving the unix path/windows path ...it comes in proper order and indentation.

      But when I am reading this file in a string and inserting the string in a database column and later on using cgi perl printing it on the webpage , it gets messed up.

      What magic is happening when I do print $htmldata in my cgi perl code so that it destroys the order and indentation of the text ?

      name    phone

      xyz    123

      abc    890

      But it is coming as :

      name phone xyz 123 abc 890 Thanks

        You've posted no code, why make people guess what $htmldata is? You don't show us how you read this input, what processing is done on the input or how you display your output. If all you do is read the data into a variable and print it within a webpage it isn't going to display in the same manner it did within your text editor. You need to learn about HTML, and basic perl. Rather than have to reiterate your problem consider putting some thought into your posts, and asking a real question, How do I post a question effectively?.

        Hi

        Yes it is just a single line , so I did not put a code. But I have mentioned that I am fetching the concatenated string from the database and I assumed that people would understand $htmldata is holding that value fetched from database.

        I am using a fetchrow_hashref function to fetch the data .

        Thanks.

        html generally ignores white space, so if you want it displayed in a particular layout then you need to add some markup.

        Try wrapping your text in a pre tag i.e.  <pre>your text here</pre>

        BTW the browser knows how to display different file types, but if your app tells the browser it's sending html and then just sends plain text, it's not surprising that you don't get the results you expected.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1015332]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (10)
As of 2014-09-17 11:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (72 votes), past polls