Wednesday, February 8, 2012

Convert Code to HTML - Perl

Convert the Code into HTML - Perl:
  0 #! /usr/bin/perl
1 use warnings;
2 use strict;
3
4 my $lineno=0;
5
6 print "<pre>";
7 foreach my $strline (<STDIN>) {
8 print "<a name=\"line$lineno\">";
9 printf "%3d", $lineno;
10 print "</a>";
11 print " <font color=\"#0000FF\">";
12 chomp($strline);
13 $strline =~ s/&/&amp/g;
14 $strline =~ s/</&lt/g;
15 $strline =~ s/>/&gt/g;
16 $strline =~ s/\t/ /g;
17 print $strline;
18 print "</font>";
19 print "<br>";
20 $lineno++;
21 }
22
23 print "</pre>\n";
24


If you swap the substitutions statements are shuffled, you will not get the desired output.