We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

includes

Medium Priority
211 Views
Last Modified: 2013-11-18
I have one script with a include to another script.  How can I use the variables from the include script in the original scrip.

require "/user.pl";

this is my require statement.
Comment
Watch Question

Author

Commented:
for instance user.pl has 1 vars in it user name.  I want to user $userName in the script.
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Commented:
like I was saying, the safest way is to use the "get" method because then you don't have to worry about variable names stepping on each other
Kavar, you are right. However it depends on what you are doing. For example if you just want to print out the final values of variables defined in a different script, I'd go with the "do" solution.

Commented:
yeah, thats a very good point :)

Author

Commented:
With using
sub get_userName {
return \$userName;
}

How do I call it from the script?

Commented:
hmmm, you should be able to use the import function of your package,
if your package does not have an import function, you can use "use"

use Modulename();
Well I consider my answer more fit to the author question (he was trying with "require"...so just changing it to a "do" is much simpler than implementing accessory functions)
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.