L
Lenny Challis
Good evening everyone.
I am currently in college doing a National Diploma in computing. Most of the
guys there haven't studied HTML or CSS or the likes and next year I think
they may be asking us to do ASP. I'm not very fond of the idea at all, so I
thought I would code my first assignment in Perl.
I had to work with 2 friends however and they have never seen perl, or even
heard of it. In fact, the looks on peoples faces when I did a presentation
on Larry Wall and Perl were kind of strange to say the least.
Anyway, to the point. I am quite new to perl myself, but I absolutely adore
it already. I am very keen to learn and make good habits from the very
beginning. I hope you don't mind, but here is a program I have made in Perl
to convert HTML files into CGI. I will use this while working with my
friends.
I would love to accept any criticism's. It is one of my first programs, but
don't miss anything. One thing I hate is getting into bad habits, so I would
like to pick them up now.
Anyway, here goes.
Thanks alot,
Lenny Challis.
___________________________
#!/usr/bin/perl -w
#this program takes in the input (html) file as command lines first argument
and output cgi file as second
use strict;
my $ofile = shift @ARGV;
my $cfile = shift @ARGV; #get the two filenames
open INPUT, "<", $ofile or die "Can't open $ofile: $!\n";
open OUTPUT, ">", $cfile or die "Can't open $cfile: $!\n"; #open
both files
print OUTPUT "\#!/usr/bin/perl\n\n";
print OUTPUT "print \"Content-type:text/html\\n\\n\";\n"; #print
the shebang and content tags
while (<INPUT>)
{
chomp($_); #getting rid of the \n's makes the code
alot more understandable
$_ =~ s/"/\\"/g; #first, escape
all quotes
$_ = "print \"" . $_ . "\\n\";\n"; #add print function
and newlines to $_
print OUTPUT $_; #add line to the output
file
}
print "Completed."; #let them know its
done
_____________________________
I am looking into getting in CGI and want to also get into mod_perl in the
future.
Thanks alot for your time.
I am currently in college doing a National Diploma in computing. Most of the
guys there haven't studied HTML or CSS or the likes and next year I think
they may be asking us to do ASP. I'm not very fond of the idea at all, so I
thought I would code my first assignment in Perl.
I had to work with 2 friends however and they have never seen perl, or even
heard of it. In fact, the looks on peoples faces when I did a presentation
on Larry Wall and Perl were kind of strange to say the least.
Anyway, to the point. I am quite new to perl myself, but I absolutely adore
it already. I am very keen to learn and make good habits from the very
beginning. I hope you don't mind, but here is a program I have made in Perl
to convert HTML files into CGI. I will use this while working with my
friends.
I would love to accept any criticism's. It is one of my first programs, but
don't miss anything. One thing I hate is getting into bad habits, so I would
like to pick them up now.
Anyway, here goes.
Thanks alot,
Lenny Challis.
___________________________
#!/usr/bin/perl -w
#this program takes in the input (html) file as command lines first argument
and output cgi file as second
use strict;
my $ofile = shift @ARGV;
my $cfile = shift @ARGV; #get the two filenames
open INPUT, "<", $ofile or die "Can't open $ofile: $!\n";
open OUTPUT, ">", $cfile or die "Can't open $cfile: $!\n"; #open
both files
print OUTPUT "\#!/usr/bin/perl\n\n";
print OUTPUT "print \"Content-type:text/html\\n\\n\";\n"; #print
the shebang and content tags
while (<INPUT>)
{
chomp($_); #getting rid of the \n's makes the code
alot more understandable
$_ =~ s/"/\\"/g; #first, escape
all quotes
$_ = "print \"" . $_ . "\\n\";\n"; #add print function
and newlines to $_
print OUTPUT $_; #add line to the output
file
}
print "Completed."; #let them know its
done
_____________________________
I am looking into getting in CGI and want to also get into mod_perl in the
future.
Thanks alot for your time.