Calling perl subroutine from shell script (sh)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Calling perl subroutine from shell script (sh)
# 1  
Old 06-21-2011
Error 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:
Code:
perl script <test>
 
#! /usr/bin/perl
 
some code goes here ......
 
sub clear()
{
some stuff ... 
}

bash script <shell.sh>
Code:
#!/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,

Last edited by pludi; 06-21-2011 at 12:53 PM..
# 2  
Old 06-21-2011
Simplest option would be to keep sub clear() in a separate pl script and invoke that code from shell.
# 3  
Old 06-21-2011
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.
# 4  
Old 06-23-2011
Hi,

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

Rrgards,
Arn
# 5  
Old 06-23-2011
Hi
Try this:


Code:
$ 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:

Code:
$ 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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Calling perl from shell script

I am calling a perl script from shell script. $ cat mah_appln_bkp_oln.ksh #!/bin/ksh . /udb/home/udbappln/.profile . /udb/home/udbappln/sqllib/db2profile Com=/udb/udbappln/utility/systemscripts/currentUMR perl $Com/backup.pl -d dbname --tsm --purgetsmcopies 21 --purgetsmlogs exit 0 ... (1 Reply)
Discussion started by: ilugopal
1 Replies

2. Shell Programming and Scripting

perl -Calling the Subroutine Only if the condition is met

Hello All, I am in the process of learning perl.I have a perl script and based on the arguments passed it would the appropriate subroutine that is defined in the script. Now, I need to check a value that is defined in the Environment variables and should call the subroutine only if the... (1 Reply)
Discussion started by: filter
1 Replies

3. Shell Programming and Scripting

calling a shell script present on another server using perl script.

Hi, I am working on a sever A. I want to write a perl script to execute a shell script persent on the server B. please help me in this. thanks in advance. (3 Replies)
Discussion started by: anandgodse
3 Replies

4. UNIX for Advanced & Expert Users

Calling PERL from a Korn shell script

I am currently in Afghanistan and do not have access to some of the resources I normally do back in the US. Just accessed this site and it looks promising! Hopefully you will not find my question too much of a waste of your time. I write mostly Korn Shell and PERL on Solaris systems for the... (2 Replies)
Discussion started by: mseanowen
2 Replies

5. Shell Programming and Scripting

How we can pass the argument when calling shell script from perl script

Can someone let me know how could I achieve this In one of per script I am calling the shell script but I need to so one thing that is one shell script call I need to pass pne argument.In below code I am calling my ftp script but here I want to pass one argument so how could I do this (e.g:... (5 Replies)
Discussion started by: anuragpgtgerman
5 Replies

6. Shell Programming and Scripting

How to accept arguments in shell script when calling in perl

I have a shell script like this: #!/bin/sh $PYTHON MetarDecoder.py < ../data/mtrs/arg1/arg2 And I'm calling it with this in perl: my $output = `./metar_parse.sh --options`; It's successful when I put in actual values for arg1 and arg2 in the shell script, but I'd like to pass arguments... (1 Reply)
Discussion started by: civilsurfer
1 Replies

7. Shell Programming and Scripting

calling perl subroutine from perl expect module

All, Is it possible to call a subroutine from the perl expect module after logging to a system that is within the same program. My situation is I need to run a logic inside a machine that I'm logging in using the expect module, the logic is also available in the same expect program. Thanks,... (5 Replies)
Discussion started by: arun_maffy
5 Replies

8. Shell Programming and Scripting

Calling perl script in shell program

How to call a perl script in shell program / shell scripting. PLS HELP ME (2 Replies)
Discussion started by: hravisankar
2 Replies

9. Shell Programming and Scripting

calling a shell script from perl

Hi all, Not sure if this is the right forum to post query regarding perl script. I have a perl script which internally calls a shell script. My problem is that the shell script should be passed command line arguments. I call a shell script from perl using: system("sript.sh"); How do... (3 Replies)
Discussion started by: gurukottur
3 Replies

10. Shell Programming and Scripting

Calling CGI Perl in Shell script [urgent]

All I want to call a perl program from my shell script. Please help me. I want to call through URL only. Like " http://www.test.com/CGI-bin/test?test=value" Please help to write this script. Thanx in advance. Thanking you Regards Deepak Xavier (0 Replies)
Discussion started by: DeepakXavier
0 Replies
Login or Register to Ask a Question