Perl 2 html

What it does
This converts your perl program to a html file for publishing at the Internet
It adds line numbers and does do indents
It colors some of the comments
So you can look at your perl code with your html browser

Usage:
Be sure the perl language is installed
Open the command prompt (start menu)
Change to de directory where your perl program is installed
Unzip the perl2html.zip file in this folder.
Type perl perl2html.pl  yourPerlProgram.pl > yourHTML_outputFile.html

Free to distribute if you link to https://www.comweb.nl

DOWNLOAD

Donation:
If you want to support my work, thanks

  
1:   #!/usr/bin/perl
2:   
3:   use strict;
4:   use warnings;
5:   
6:   
7:   # check the users input
8:   if ($#ARGV==-1) { die "\nUSAGE:\n  perl perl2html.pl myPerlFile.pl > myPerlFile.html\n  (creates a html file contaning formated perl code) from myPerlFile.pl\n\n";    }
9:   my $filename=$ARGV[0];
10:  
11:  my $number_of_lines=0;
12:  my $current_line=undef;
13:  my $indent=0;
14:  my $next_line_do_indent=0; 
15:  
16:  print <<HTML_START;
17:  <!DOCTYPE html> 
18:  <html>
19:  <head>
20:  <meta name="generator" content="perl2html.pl comweb Netherlands">
21:  <meta http-equiv="content-type" content="text/html; charset=utf-8">
22:  <title>html of $filename</title>
23:  <style>
24:  body  { font-family: sans-serif; background-color: #22EEFF; color: #000000; }
25:  pre 
26:  {
27:    display: block;
28:    font-family: monospace;
29:    white-space: pre;
30:    margin: 1em 0;
31:  }
32:  .comment { color: green;}  
33:  </style>
34:  </head>
35:  <body>
36:  <pre>  
37:  HTML_START
38:  
39:  open(FH, '<', $filename) or die $!;
40:  while(<FH>)
41:  {
42:    
43:    $current_line=$_;
44:    
45:    #remove all tabs \t
46:    $current_line =~ s/\t//g;
47:    
48:    #remove all \r\n
49:    $current_line =~ s/(\r)|(\n)//g;
50:    
51:    #replace all "" with &quot;;
52:    $current_line =~ s/\&/\&amp;/g;
53:    
54:    #replace all < with &lt;
55:    $current_line =~ s/</\&lt;/g;
56:    
57:    #replace all > with &gt;
58:    $current_line =~ s/>/\&gt;/g;
59:    
60:    #replace all "" with &quot;;
61:    $current_line =~ s/\"/\&quot;/g;
62:    
63:    #remove spaces on the left
64:    $current_line =~ s/^ *//g;
65:    
66:    if ($next_line_do_indent>0)
67:    {
68:      $indent+=$next_line_do_indent;
69:      $indent+=$next_line_do_indent;
70:      $next_line_do_indent=0;
71:    }
72:    
73:    # line a comment then ignore (starts with #)
74:    if ( !( $current_line =~ m/^#/) )
75:    {
76:      # count the brackets
77:      my @matches_right= ($current_line =~ m/{/g);  
78:      my @matches_left = ($current_line =~ m/}/g);  
79:      my $bracket_shift=($#matches_right+1)-($#matches_left+1);
80:      if ($bracket_shift<0 ) 
81:      { 
82:        if ($indent<0) { $indent=0; } # error checking       
83:        $indent+=$bracket_shift;
84:        $indent+=$bracket_shift;
85:      } 
86:      if ($bracket_shift==0) {} # do nothing
87:      if ($bracket_shift>0 ) { $next_line_do_indent=$bracket_shift;} 
88:      
89:    } else
90:    { 
91:      $current_line="<span class=\"comment\">".$current_line."</span>";
92:    }
93:    
94:    # construct the line numbering assuming max 9999 lines (4 digits)
95:    # and print it
96:    $number_of_lines++;
97:    printf ("%-5s", $number_of_lines.":");
98:    
99:    printf("%".$indent."s","");
100:   print $current_line."\n"; 
101: }
102: 
103: close(FH) or die $!;
104: 
105: print <<HTML_END;
106: </pre>
107: <hr>
108: Output created with perl2html from <a href="https://www.comweb.nl">https://www.comweb.nl</a><br>
109: \&copy;2019 Comweb Netherlands, <a href="mailto:sales2\@comweb.nl?subject=perl2html">sales2\@comweb.nl</a><br>
110: </body>
111: </html>
112: HTML_END
113: 

Output created with perl2html from https://www.comweb.nl
©2019 Comweb Netherlands, sales2@comweb.nl