Calling perl subroutine from shell script (sh)

Hi,

ive a perl script, where it has a subroutine clear() in it, and i've one shell script which runs in background, from that shell script i wanted to call subroutine which is in perl script, that's perl script is not module, just simple script.

Eg:

perl script <test>
 
#! /usr/bin/perl
 
some code goes here ......
 
sub clear()
{
some stuff ... 
}

bash script <shell.sh>

#!/bin/sh
-- some stuff here -- 
 
if [ "$FSIZE" -ge "$SIZE" ] ; then
 
< i need to call subroutine which is defined in perl script < test> >
 
fi 

i tried using perl -m<module> . as my perl is not a module, it didnt work.

please help..

Thanks,

Simplest option would be to keep sub clear() in a separate pl script and invoke that code from shell.

Hi getmmg,
No i don't want to write new Perl script, as the script has clear subroutine, i wanted to use the existing Perl script subroutine <test>, from bash <shell.sh>. As shell script will call if that condition satisfies. please help with this existing perl script only.
Thanks.

Hi,

Anyone got solution ?? i'm not getting anything.. please help ..

Rrgards,
Arn

Hi
Try this:

$ cat a.pm
#! /usr/bin/perl

my $x="welcome";
sub clear()
{
   print "inside clear of perl...\n";
}
1
$

Now, from the shell trying to execute the perl function:

$ perl -Ma -e 'clear()'
inside clear of perl...
$

where -M is for the module, and "a" indicates to pick the module named a.pm. The same line you can put inside your shell script as well.

Guru.