Solved

includes

Posted on 2004-04-05
12
178 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.
0
Comment
Question by:brink1978
  • 4
  • 3
  • 2
12 Comments
 

Author Comment

by:brink1978
Comment Utility
for instance user.pl has 1 vars in it user name.  I want to user $userName in the script.
0
 
LVL 10

Accepted Solution

by:
Kavar earned 50 total points
Comment Utility
the safest way to do this....

in user.pl include a function that returns a reference to the variable

sub get_userName {
return \$userName;
}


0
 
LVL 11

Assisted Solution

by:lbertacco
lbertacco earned 50 total points
Comment Utility
Don't use "require", but "do" as in:

do "/user.pl";

then you will be able to use the veriables defined in user.pl
0
 
LVL 10

Expert Comment

by:Kavar
Comment Utility
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
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 11

Expert Comment

by:lbertacco
Comment Utility
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.
0
 
LVL 10

Expert Comment

by:Kavar
Comment Utility
yeah, thats a very good point :)
0
 

Author Comment

by:brink1978
Comment Utility
With using
sub get_userName {
return \$userName;
}

How do I call it from the script?
0
 
LVL 10

Expert Comment

by:Kavar
Comment Utility
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();
0
 
LVL 11

Expert Comment

by:lbertacco
Comment Utility
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)
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now