How can I call one Perl script from another?

If you would like to make a call to, or reference, a Perl script from within a different Perl script, you can accomplish this a system(), exec() or the backtick operator to the path for Perl. For example:

system("/usr/bin/perl /path/to/my_script.pl ");

Or store output to array:

@myarray = `/usr/bin/perl mysecondperlscript.pl`;

How to call perl or php script from HTML file?

Easiest way to do this is call php/perl script as javascript. Since javascript is client side stuff, php or perl script need to writeback output using javascript commands only. This is useful if you have lots of HTML files and would like to do some server side processing. For example Tips & Tricks section on our site has lots of html pages which uses code as follows:

<script language="JavaScript" type="text/javascript" src="http://rss.cyberciti.biz/rss2html.php?u=http://blogs.cyberciti.biz/feed/">
<script>

Above code generates recent post posted in blogs.cyberciti.biz/hm blog. Main advantage of this technique is simple, you can use it from HTML file and your javacode is also hidden (although other better ways exists to do this).

(A) An example of PERL, create file called html.pl as follows and put into your cgi-bin directory:

#!/usr/bin/perl
use strict;
use warnings;
use CGI;
my $q = CGI->new();
my $info = "Server: ". $ENV{'SERVER_NAME'} . "
Script name: ". $ENV{'SCRIPT_NAME'}; # need to send header otherwise sky will fall on you print $q->header(); # always get back to user after perl code print "document.write('Hello world
I am called from HTML page $ENV{'HTTP_REFERER'}
');"; print "document.write('$info');";

Add following line to your HTML code (replace mydomain.com with your real domain name):

<script language="JavaScript" type="text/javascript" 
src="http://www.mydomain.com/cgi-bin/html.pl"
<script>

(B) An example of PHP, create file called html.php as follows and put into your webserver directory:

<?php
 $ref = $_SERVER['HTTP_REFERER'];
 $ser = "Server: ". $_SERVER['SERVER_NAME'] .  "
Script name: ". $_SERVER['SCRIPT_NAME']; echo "document.write('Hello World
I am php code called from HTML file:' );"; echo "document.write('$ref
');"; echo "document.write('$ser');"; ?>

Add following line to your HTML code (replace mydomain.com with your real domain name):

<script language="JavaScript" type="text/javascript" 
src="http://www.mydomain.com/html.php"
<script>

PHP code is bit easier to use as compare to PERL.

How to redirect url with perl script

It is common scenario when you need to tell the browser to redirect or look elsewhere for a page because you don’t want to produce a document yourself.

For example http://mydomain.com/rd.pl?url=http://blogs.mydomain.com should redirect to a page/url http://blogs.mydomain.com

Here is perl code to redirect web page to http://blogs.cyberciti.biz/hm/:

#!/usr/bin/perl

use strict;

use warnings;

my $url = "http://blogs.cyberciti.biz/hm/";

print "Location: $url\n\n";

However this code misses the functionality to get URL as input, this can be easily done using standard CGI module. Please see rd.pl script code.

i) Just download the rd.tar.gz script (click on download) or use wget command at shell prompt:
$ wget https://www.cyberciti.biz/download/perl_scripting/cgi/rd.pl.tar.gz

ii) Copy rd.pl script to your cgi-bin directory or directory where perl script execution allowed
iii) Suppose your domain name is cyberciti.biz and you put this script in directory called cgi-bin then to execute this script simply type http://cyberciti.biz/cgi-bin/rd.pl?url=http://www.goole.com or even ftp url http://cyberciti.biz/cgi-bin/rd.pl?url=ftp://ftp.freebsd.org/