| | |
How to invoke a perl program from a perl program.
Please support our Perl advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Sep 2005
Posts: 2
Reputation:
Solved Threads: 0
I am invoking a perl program from the shell script. the shell script is named as sam.sh
#!/usr/bin/sh
perl check1.pl cr_incr08292005 n n //cr_incr08292005 is the directory under a directory where sam.sh,slp.pl and check1.pl are stored.
The check1.pl is as below. The check1.pl inturn call another perl program slp.pl.
#!/usr/local/bin/perl
$runAutomatic=$ARGV[1];
$skipCaseClean=$ARGV[2];
if( -d $ARGV[0])
{
print("Directory is $ARGV[0]");
}
if ($runAutomatic eq "n"){ print "No run automatic";
}
if ($skipCaseClean eq "n") { print "No skipping bad cases";
$i=1;
}
print "calling";
system "perl slp.pl" || die "Cannot open"
But when i run the main program using the command
sh sam.sh
The output is as below.
This is from slp.pl
Directory is cr_incr08292005
No run automatic
No skipping bad cases
calling
So the problem is when ever the external perl program is invoked "the system command is called first and then rest of the statements in th program is executed". Please provide me the solution for this problem.
#!/usr/bin/sh
perl check1.pl cr_incr08292005 n n //cr_incr08292005 is the directory under a directory where sam.sh,slp.pl and check1.pl are stored.
The check1.pl is as below. The check1.pl inturn call another perl program slp.pl.
#!/usr/local/bin/perl
$runAutomatic=$ARGV[1];
$skipCaseClean=$ARGV[2];
if( -d $ARGV[0])
{
print("Directory is $ARGV[0]");
}
if ($runAutomatic eq "n"){ print "No run automatic";
}
if ($skipCaseClean eq "n") { print "No skipping bad cases";
$i=1;
}
print "calling";
system "perl slp.pl" || die "Cannot open"
But when i run the main program using the command
sh sam.sh
The output is as below.
This is from slp.pl
Directory is cr_incr08292005
No run automatic
No skipping bad cases
calling
So the problem is when ever the external perl program is invoked "the system command is called first and then rest of the statements in th program is executed". Please provide me the solution for this problem.
•
•
Join Date: Sep 2005
Posts: 2
Reputation:
Solved Threads: 0
[QUOTE=manju13]I am invoking a perl program from the shell script. the shell script is named as sam.sh
#!/usr/bin/sh
perl check1.pl cr_incr08292005 n n //cr_incr08292005 is the directory under a directory where sam.sh,slp.pl and check1.pl are stored.
The check1.pl is as below. The check1.pl inturn call another perl program slp.pl.
#!/usr/local/bin/perl
$runAutomatic=$ARGV[1];
$skipCaseClean=$ARGV[2];
if( -d $ARGV[0])
{
print("Directory is $ARGV[0]\n\n");
}
if ($runAutomatic eq "n"){ print "No run automatic\n\n";
}
if ($skipCaseClean eq "n") { print "No skipping bad cases\n\n";
$i=1;
}
print "calling\n\n";
system "perl slp.pl" || die "Cannot open"
Ths program slp.pl is as below.
#!/usr/local/bin/perl
print "This is from slp.pl\n\n";
But when i run the main program using the command
sh sam.sh
The output is as below.
This is from slp.pl
Directory is cr_incr08292005
No run automatic
No skipping bad cases
calling
So the problem is when ever the external perl program is invoked "the system command is called first and then rest of the statements in th program is executed". Please provide me the solution for this problem.
#!/usr/bin/sh
perl check1.pl cr_incr08292005 n n //cr_incr08292005 is the directory under a directory where sam.sh,slp.pl and check1.pl are stored.
The check1.pl is as below. The check1.pl inturn call another perl program slp.pl.
#!/usr/local/bin/perl
$runAutomatic=$ARGV[1];
$skipCaseClean=$ARGV[2];
if( -d $ARGV[0])
{
print("Directory is $ARGV[0]\n\n");
}
if ($runAutomatic eq "n"){ print "No run automatic\n\n";
}
if ($skipCaseClean eq "n") { print "No skipping bad cases\n\n";
$i=1;
}
print "calling\n\n";
system "perl slp.pl" || die "Cannot open"
Ths program slp.pl is as below.
#!/usr/local/bin/perl
print "This is from slp.pl\n\n";
But when i run the main program using the command
sh sam.sh
The output is as below.
This is from slp.pl
Directory is cr_incr08292005
No run automatic
No skipping bad cases
calling
So the problem is when ever the external perl program is invoked "the system command is called first and then rest of the statements in th program is executed". Please provide me the solution for this problem.
Ok, try this code fixup:
Here's what I've done:
1. I cleaned up the alignment and formatting of your syntax.
2. I took out the seemingly useless
3. I literalized the system() command, and threw in some parenthesis for sanity's sake.
4. Most importantly I added a semi-colon after the die() command.
I hope that fixes things up for you.
EDIT: Keep in mind, Perl's syntax is ugly as is, so - and this goes to everyone who writes in Perl - try and make your code as visually appealing and as un-cryptic as possible; one command/small conditional/assignment a line.
Perl Syntax (Toggle Plain Text)
#!/usr/local/bin/perl -w ############### check1.pl ############### $runAutomatic = $ARGV[1]; $skipCaseClean = $ARGV[2]; if ( -d $ARGV[0] ) { print "Directory is $ARGV[0] \n\n"; } if ( $runAutomatic eq 'n' ) { print "No run automatic. \n\n"; } if ( $skipCaseClean eq 'n' ) { print "No skipping bad cases. \n\n"; } system("perl slp.pl") or die("Cannot open.");
Here's what I've done:
1. I cleaned up the alignment and formatting of your syntax.
2. I took out the seemingly useless
$i = 1; assignment from the third "if" conditional.3. I literalized the system() command, and threw in some parenthesis for sanity's sake.
4. Most importantly I added a semi-colon after the die() command.
I hope that fixes things up for you.

EDIT: Keep in mind, Perl's syntax is ugly as is, so - and this goes to everyone who writes in Perl - try and make your code as visually appealing and as un-cryptic as possible; one command/small conditional/assignment a line.
Last edited by indienick; Jul 24th, 2006 at 6:04 pm.
Angel-headed hipsters burning for the ancient heavenly connection, to the starry dynamo in the machinery of the night.
-Ginsburg
Don't tell me to "google it" - I already have.
-Ginsburg
Don't tell me to "google it" - I already have.
•
•
Join Date: Jul 2006
Posts: 1
Reputation:
Solved Threads: 0
An even cleaner one:
Note that system returns the exit code, which normally is 0, and hence system ... or die as in the previous fixup always dies...
Perl Syntax (Toggle Plain Text)
#!/usr/local/bin/perl use strict; use warnings; @ARGV == 3 or die "usage: check1.pl DIR AUTOMATIC SKIP"; my ( $dir, $run_automatic, $skip_case_clean ) = @ARGV; -d $dir and print "Directory is $dir\n\n"; $run_automatic eq 'n' and print "No run automatic.\n\n"; $skip_case_clean eq 'n' and print "No skipping bad cases.\n\n"; system( 'perl', 'slp.pl' ) == 0 or die "System call failed: $?";
Last edited by John Bokma; Jul 25th, 2006 at 11:21 pm.
I can be hired as a professional Perl programmer and web developer.
![]() |
Similar Threads
- passing parameters from a perl program to a c++ .exe file (Perl)
- calling one perl program from within another (Perl)
- Call Perl program from sed. (Legacy and Other Languages)
- to use c++ program from perl (Perl)
Other Threads in the Perl Forum
- Previous Thread: PERL software engineers NEEDED
- Next Thread: Perl CSV question
| Thread Tools | Search this Thread |






