Embedding Perl into Perl

This article describes embedding a Perl script into a Perl script. The program executes through Common Gateway Interface (CGI), which reads ASCII file through file upload method and displays content of the file. The Perl script upload.pl is called through the Perl script file-upload.pl using function eval{}. This program can be modified to call by reference function, to access other system programs too.


    <title>File Upload</title>
    <form method="post" action="/cgi-bin/file-upload.pl" 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 "upload.pl" };
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 (@_);


Most Popular Posts

TNEB Bill Calculator

TNEB Bill Calculator (New)

Technical Questions