Solved

includes

Posted on 2004-04-05
12
181 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
12 Comments
 

Author Comment

by:brink1978
ID: 10756505
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
ID: 10756824
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
ID: 10756867
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Expert Comment

by:Kavar
ID: 10756886
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
 
LVL 11

Expert Comment

by:lbertacco
ID: 10757272
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
ID: 10757400
yeah, thats a very good point :)
0
 

Author Comment

by:brink1978
ID: 10781228
With using
sub get_userName {
return \$userName;
}

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

Expert Comment

by:Kavar
ID: 10808447
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
ID: 11043163
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to get all the API from website? 11 129
Randomize in Owl Carousel v1.3.2 6 104
Using Third Party DLL with Access VBA 14 52
How to build a web site 17 60
Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

730 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