wrapper script calling anotherr script


B

bjlockie

I want to create a wrapper script (testa.pl) that defines variables (like $b) and can execute another perl program (testb.pl) that can access those variables.

I tried:
$ testa.pl 'testb.pl' but it didn't work.
I don't think eval is what I need but 'use' doesn't work on variables.


::::::::::::::
testa.pl
::::::::::::::

#!/usr/bin/perl -w

#use strict;
use warnings;

my $realScript = $ARGV[0];

(defined($realScript)) or die "Must specify a script\n";

print "This is $0\n";
my $b = 10;
eval $realScript;

print [email protected];



::::::::::::::

testb.pl

::::::::::::::

#!/usr/bin/perl -w

use strict;
use warnings;

print "This is $0, b=$b (should be 10)\n";
 
Ad

Advertisements

B

bjlockie

It's a strange thing to want to do, but Perl knows how to do this.

You want to use "do".

I am using someone else's scripts that each have config data by using 'use configa'.
There is 'configb', 'configc', etc.
The current way of changing the config is to modifiy each 'use' in all the scripts.
With the wrapper, I can have the 'use configx' in one place and use 'do' to call the other scripts.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top