Operating System - HP-UX
1833609 Members
3655 Online
110062 Solutions
New Discussion

Re: Script which calls another perl script

 
SOLVED
Go to solution
Varghese Mathew
Trusted Contributor

Script which calls another perl script

Experts,

Could someone guide me on "how to pass on a variable' value to the called in script which is written in perl", where the calling i.e; the parent script is standard Unix Posix shell.

I'm using the Net /FTP functionality in Perl for my scripting. So from my parent Unix script, i will gather the list of files to be trasferred, and that list will be handed over to the Perl script one by one, using which I would have better error code trappings or so.

Thanks in advance.
Cheers !!!
Mathew.

Cheers !!!
6 REPLIES 6
Steve Labar
Valued Contributor

Re: Script which calls another perl script

When passing arguments to a Perl script, you use them via the @ARGV. In your shell script call the Perl script using the list as an argument.

Good Luck.

Steve
Steven E. Protter
Exalted Contributor

Re: Script which calls another perl script

attached is a script that takes and processes command line arguments.

it is a perl script.

You can process as many arguments seperated by spaces as you need by modifying this script.
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
H.Merijn Brand (procura
Honored Contributor

Re: Script which calls another perl script

Read this thread: http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x0e7fef70e827d711abdc0090277a778c,00.html

Tom asked the same, and got the right answers
Enjoy, Have FUN! H.Merijn
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Script which calls another perl script

Hi:

This should serve as an example:

ftpget.pl file1 file1 file3

See the attached Perl script.
------------------------
Another useful technique is getopts:

use Getopt::Std;
use English;
use strict;


our ($opt_m,$opt_a,$opt_c,$opt_e);
my $mode = 0;
my $knt = 0;
my $epoch = 0;
getopts('mace:');

if (defined($opt_e))
{
$epoch = $opt_e;
++$knt;
}
if (defined($opt_m))
{
$mode = 0;
++$knt;
}
if (defined($opt_a))
{
$mode = 1;
++$knt;
}
if (defined($opt_c))
{
$mode = 2;
++$knt;
}

Note that the 'e' arg is followed by a colon and thus expect a value (-e 45) to be supplied while the others simply expect to be found (or not).
If it ain't broke, I can fix that.
H.Merijn Brand (procura
Honored Contributor

Re: Script which calls another perl script

Recent versions op Getopt::Long make this *MUCH* easier :)

use strict;
use warnings;
use Getopt::Long qw(:config bundling nopermute);

my $mode = 0;
my $epoch = 0;
GetOptions (
"e:i" => \$epoch,
"m" => sub { $mode = 0 },
"a" => sub { $mode = 1 },
"c" => sub { $mode = 2 },
} or die "bad option";
Enjoy, Have FUN! H.Merijn
H.Merijn Brand (procura
Honored Contributor

Re: Script which calls another perl script

Getopt::Long makes this *MUCH* easier :)

use strict;
use warnings;
use Getopt::Long qw(:config bundling nopermute);

my $mode = 0;
my $epoch = 0;
GetOptions (
"e:i" => \$epoch,
"m" => sub { $mode = 0 },
"a" => sub { $mode = 1 },
"c" => sub { $mode = 2 },
} or die "bad option";
Enjoy, Have FUN! H.Merijn