Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re^2: I just want to include another file

by Cap'n Steve (Friar)
on Sep 14, 2004 at 18:51 UTC ( [id://390943]=note: print w/replies, xml ) Need Help??

in reply to Re: I just want to include another file
in thread I just want to include another file

It just seems silly to me to clutter the code with extra modules and deal with exporting when I'll want the same symbols every time. I'll try use() again, I think having to declare variables in both files was what was messing me up. It seems like it should work just by using our() in the included file though.
  • Comment on Re^2: I just want to include another file

Replies are listed 'Best First'.
Re^3: I just want to include another file
by hmerrill (Friar) on Sep 15, 2004 at 11:55 UTC
    I don't have code at my fingertips to show you, but you don't have to declare variables in both files. If the export is done properly in the module, you can simply refer to the variables in the code that does the "use". I hope I'm not oversimplying here - it's been a while since I've done this, and I'm not actively using Perl now.

    I also think when I did create modules that I used a simplified approach of not doing "export"s at all. The "use" still worked the same, but to refer to variables in the module I had to use the module name, something like this:

    use lib '/path/to/my/module/directory'; use MyMod; print "MyMod var1 value is $MyMod::var1\n";
    Again, not sure if this is exactly right, but it should be close. I liked this approach because looking at the code you can always tell *where* a variable comes from - you don't need to go hunting around for it if you see that it hasn't been declared in the current module. You *are* using warnings(-w), strict, and declaring all your variables with "my", right??


Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://390943]
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (5)
As of 2024-04-23 21:08 GMT
Find Nodes?
    Voting Booth?

    No recent polls found