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!

use/require file problem

Status
Not open for further replies.

julie25

Programmer
Aug 7, 2003
22
FR
hi,
I would like to use other files in my main file.

- What do I have to write in the other files? (All use::* ?)(this may be stupid question ...)
- Do I have to redefine all global variables?

I wrote:
####Main file, I introduced with:
require "MyFile2.pl";

####MyFile2:
One fonction that calls for a toplevel creation from my main window(argument of the fonction)...

sub func{
my $mw = @_;
$sw = $mw->Toplevel;
}
return 1;

The error tells me that i cannot create a toplevel without an object reference...

Thanks for help,

Julie
 
Instead of

my $mw = @_;

try:

my $mw = shift @_;

Otherwise, it appears that your understanding of "including" code is correct. The easiest way to understand requires is this:

Where ever Perl sees 'require' in your code, it stops what it's doing, finds the required file, and evaluates the contents of the file. Hopefully it's valid perl code :)
When it's done evaluating the external file, it goes back to the original code and continues parsing.

So while most people use 'requires' to load up some subroutines or data structures, it is possible to have code execute when the require is done, like so:
Code:
# main file
print "Hey hey hey!\n";
require 'fat_albert_says.pl'
print "*plop*\n";
__END__

# now in 'fat_albert_says.pl'
print "Bombs away!\n";

1;
__END__
But doing stuff like that is pretty uncommon.

Hope that helps you, Julie.

--jim
 
whatever is your main script all you have to do is use require the script library etc. in that main file not all of them. I always you tons of subs the biggest problem that happens is when you try to use a var that hasn't been set yet.
 

thank you very much Jim and Arcnon for your help!
I think it will function now.
:)

Julie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top