Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Import Value 2

Status
Not open for further replies.

Porshe

Programmer
Jun 5, 2001
38
0
0
US
Hello! How can I import a value (say $out=123) from find.pl to last.pl?

Thanks,
Porshe
 
You could make a module to hold $out:

my_module.pm (this is the name of the file)
-----------------------------
package my_module;
$out = "123";
1;


last.pl
-----
#!/path/to/perl
use strict;
use my_module; ### works as long as my_module.pm is
### in the same directory, or is in the
### perl search directory @INC. If
### my_module is in a different directory, then you'll need to use
### "use lib " to refer to the directory that
### my_module *sits in*.
print "\$out = $out";

=============================================

I think that should work. If you're going to use modules, you should read up on them - once you get used to using them, they're great. But in the beginning it can be a little trying. :)

"perldoc perl" says this about perl modules:
perlmod Perl modules: how they work
perlmodlib Perl modules: how to write and use

so you can do "perldoc perlmod" to see how perl modules work.

HTH.
Hardy Merrill
Mission Critical Linux, Inc.
 
An easier way than using modules is just to "require" a .pl file. It will essentially add the code from the required file at the location of the require command. I use this a lot to pull in configuration variables. For example, here's a params.pl file:
Code:
# This is file params.pl
$param1 = "12345";
$param2 = "abcde";
# Do not change the last line!
1;
And here's the statement you would add to your program to use it:
Code:
require "params.pl";
The require statement will search the perl include path for the required file, so if you put the file in your cgi directory you don't need a pathname on it. Otherwise you could store it somewhere else, and add that path to the include path:
Code:
push(@INC, "/path/to/params");
require "params.pl";
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top