Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re: require issue.

by osunderdog (Deacon)
on Mar 02, 2007 at 12:56 UTC ( [id://602871]=note: print w/replies, xml ) Need Help??

in reply to require issue.

I ran through this with the debugger:

$perl -d Loading DB routines from version 1.25 Editor support available. Enter h or `h h' for help, or `man perldebug' for more help. main::( require ""; DB<1> S newform* newform::func1 newform::someFile newform::someFile1 DB<2> S main* main::BEGIN DB<3>

So the functions you are requiring are getting included in the package.. because that's where you require them.

One thing that require does is "check for redundant loading, skipping already loaded files." So in this case, the required script is getting included in the package. The package is compiled first. The second time that require is called is at the main, however this is after the package has been compiled. So at that time, the require fails/does not include the package a second time.

So I changed the main code to scope the function call:

use strict; require ""; use newform; &newform::someFile(); &newform::func1();

and it works as expected.

Alternatively you could do this in your main:
sub BEGIN { require ""; }

Which would force the require before the newform package, however you would have to also change the call to someFile in the newform package:


which might not make sense.

Hazah! I'm Employed!

Replies are listed 'Best First'.
Re^2: require issue.
by ant (Scribe) on Mar 02, 2007 at 13:29 UTC
    After posting that request for help I continued looking for a solution and came up with this.

    in I commented out the require statement
    package newform; #require ""; sub func1 { main::someFile1(); print "Inside func1"; } 1;
    I left the Requires('') in the, Then, when in the and I wanted to use the someFile1 function I called main::someFile1(); This seemed to work!

    Thanks all for looking into this also.
      Or put a package main; at the beginning of; that way each other file that uses something from makes sure that it's loaded, but always knows what package to expect it to be loaded into.

Log In?

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2024-07-24 20:40 GMT
Find Nodes?
    Voting Booth?

    No recent polls found

    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.