Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

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

by Utilitarian (Vicar)
on Jan 25, 2013 at 12:20 UTC ( [id://1015335]=note: print w/replies, xml ) Need Help??


in reply to Re: How to convert a text file to a HTML file
in thread How to convert a text file to a HTML file

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

Replies are listed 'Best First'.
Re^3: How to convert a text file to a HTML file
by ghosh123 (Monk) on Jan 25, 2013 at 12:43 UTC

    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

      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.

      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.

        First off, you replied to yourself, you've posted here many times, if you wish to reply to someone click the "reply" link within the post in question. Secondly you're still missing the point, you don't mention how you read the input data, how you process it (parse it from the format it's in into HTML) and how you display it. But I mentioned this already, among other things. If you continue to ignore what people say in response to your questions then you're wasting your time.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-04-18 03:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found