Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

convert text to html 1

Status
Not open for further replies.

DanKay1

Programmer
Jun 9, 2004
54
US
I need to convert textfile to HTML.
Example of textfile below:

textfile.txt
a. Line 1
b. Line 2

HTML
Create HTML page with the Name of todays date.
And inside color code the lines and remove a. and b. in front of them until EOF.

if first char is a. then line should be red.
if first char is b. then line should be blue.

Can anyone help me with the code. I am learning Perl at this moment want to take the code and make more advanced.

Thanks in advance.
 
Have you tried to do this yourself? If so, what are you having problems with? Maybe post some code.
 
Maybe something like this? (Please excuse my meager attempts and correct as necessary)
Code:
# ...
print '
<style type="text/css">
.red { color: red; }
.blue { color: blue; }
</style>';

while (<TXTFILE>)
{
  if (/^[ab]\./)
  {
    $line = s/^(a\.)/<span class="red">/;
    $line = s/^(b\.)/<span class="blue">/;
    $line .= "</span>";
  }
  print $line;
}

--Chessbot

There is a level of Hell reserved for probability theorists in which every monkey that types on a typewriter produces a Shakespearean sonnet.
 
Thanks guys let me try it. I am rookie in perl.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top