Sunday, June 6, 2010

Embedding Perl into Perl

This article describes embedding a Perl script into a Perl script. This program is an Common Gateway Interface, which reads ASCII files through file upload and displays content of the file. The Perl script is called through the Perl script using function eval{ }. This program can be modified to call by reference function, to access in other programs too.
<title>File Upload</title>
<form method="post" action="/cgi-bin/" enctype="multipart/form-data">
Enter the file to upload:<br>
<input name="file" size="45" type="file"><br>
<input name="reset" type="reset">
<input name="submit" value="Upload" type="submit">
eval { require "" };
my @x = upload();
print "Content-type: text/html\n\n";
print "<font face='courier new'>",@x,"</font>";
use strict 'refs';
use lib '..';
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
sub upload()
my $file = param('file');
while (<param('file')>)
@_ = <$file>;
return (@_);

Note: Both Perl scripts must granted file permission (0755)


Post a Comment