Does anyone know how - or if it's even possible - for a child perl script to inherit the variables of a parent perl script? In a shell script, you would use "export" for example. I am running Perl 5.8.
Basically, let's say "perl1.pl" calls "perl2.pl" and I want "perl2.pl" to inherit the value of "$perl1_var" without passing it as a parameter. Any idea how to do this ? I've done some research and don't see this as even being an option.
That depends on what you mean by "parent" and "child" scripts.
If a Perl script invoked another Perl script through a shell with backticks, or system() for instance, then of course you can't. Even variables will not work as they are separate processes. Only some sort of IPC or command-line arguments will work. Probably you are not asking for this, but as a "parent" and "child" relationship, this seems to fit the terminology.
The Perl require() doesn't really have much a parent or child relationship. It just means to load and execute the code in an external file, but the execution environment is just exactly the same one.
Because $a is a package global (in package "main" here), its value is retained throughout the entire script unless its value is modified. Scoping has no effect, so you can always refer to it anywhere in the script.
But this won't work because my imposes lexical scope:
local() is okay, though, because it has a dynamic scope. Slightly better than unrestricted package global:
There's nothing wrong with passing parameters around. In fact, it is usually a bad idea to use package globals unless you have established different packages (namespaces) to avoid variable name clashes.
Or you can use OOP. Then you probably can put everything into the object so that you only have one thing to pass around.
Thanks for the reply cbkihong. I've only started with perl about 4 months ago and haven't done much calling of one script from another, and even less of what I'm trying to do, which is basically have the same script invoke multiple instances of itself (it's a menu generator). I was hoping to give values to a set of variables once and make them available from any instance of the script.
Your reply is very thorough and greatly appreciated. And your solutions are beyond where I am with perl (yet!). I will most likely do this via 'ksh' where I can source script calls and export variables. Perl is a much better scripting language so it's unfortunate, but in this case, ksh is proving to be the better fit.
I am using python 3.4. Below is the exception I am getting-
Traceback (most recent call last):
File "./oop.py", line 20, in <module>
y = DerivedClass("Manu")
File "./oop.py", line 15, in __init__
super().__init__(self,value)
TypeError: __init__() takes 2 positional arguments but... (2 Replies)
Hi ,
If i start mysqld or httpd as root user which inturn starts them as "mysql" or "apache" user, will the ulimit of "root" user or ulimit of "mysql/apache" user be set for the mysql/apache processes.
My understanding is that the ulimit of the user who initiates the process(root in this... (2 Replies)
Hi,
In multi-level inheritance:
class A {
public:
void fun() { cout << "A" << endl; }
};
class B : public A {
public:
void fun() { cout << "A" << endl; }
};
class C : public B { };
int main() {
C c;
c.fun(); // Ans: A
} (1 Reply)
package Inventory_item;
sub new {
my($class) = shift;
bless {
"PART_NUM" => undef,
"QTY_ON_HAND" => undef
}, $class;
}
package main;
$item = Inventory_item->new();
Can any one please help me in brief explaining the line... (5 Replies)
Hi friends,
I hope u people are ok and doing fine.
I have this small problem with the derived class. I have created te base class and there is a small problem with the definition of the derived class which the compiler is pointing out, could you please help me. Here is my code
#ifndef... (2 Replies)
Is none of you using WLM? A search gives no matches....
Anyway, I have set up a class with inheritance = yes. In the rules characteristics I have chosen a shell script as an application. This script is caught by the class, but not the child processes, which have the PID of the script as the... (6 Replies)
1) I have the below code in concattxnrecords.sh shell script and it is calling the genericVars.sh shell script which is mentioned as below has some code inside it which would intialize some variables in it, now my question is will this shell script would inherit those variable definitions or not... (3 Replies)
Hi,
I have a number of Makefiles, including a couple of files that I include in Makefiles, a few scripts that are executed through Makefiles, and I have problems with environment variables that are not inherited to the scripts properly.
Simplified scenario:
rootdir/Makefile:
all:
... (1 Reply)