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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get variables of main program in a module?

Status
Not open for further replies.

liuwt

Programmer
Jul 15, 2003
35
DE
Hi,

how can I get the values of variables, that I had declared in my main routine, in a module? I know I could pass them as parameters to the subroutine, but I would like to know wether there is another (better) solution?

e.g.

use my;
$t="hello";

---my.pm----
...
print $t;
...

Thanks

Smash your head on keyboard to continue...
 
Hi arn0ld,

could please nearer explain it? I thought @ARGV is only used for reading from the command line, or am I false?

Greetings

--
Smash your head on keyboard to continue...
 
you are right - poor reading skills on my part.
From PrgPerl,ch10, .pm:


print "Module\n";
foreach (sort keys %main::) {
print "$_\n";
}
1

excludes my variables
includes main GLOBALS
"use" must be after main declarations
 
a "require" (instead of "use") can be placed at the start of the main program.
 
Using your example...



use my;
$t="hello";

---my.pm----
...
print $main::t;
...
 
a module is Perl code - man perlmod

#2 different print outputs:
print "T=$t\n";
$t="hello\n";
print "T=$t\n";

use runs at compile time. require runs at run time.

$t="Hello\n";
require my;

vs:
require my;
$t="Hello\n";




 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top