Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Answer: How can I write and call subroutines in separate files?

( #68925=categorized answer: print w/ replies, xml ) Need Help??

Q&A > subroutines > How can I write and call subroutines in separate files? contributed by cLive ;-)

If you're using strict, you need to declare the package name as well (and it's probably best to if your code's big enough to suggest splitting :)
# file one use File2; File2::setup(); main(); # or ::main() (this package) or main::main() very specific # "default" package name for main script (the one requiring other file +s) is 'main' # print var foo from package File2 print $File2::foo . "\n"; sub main { print "I am in the main subroutine.\n"; } # file 2 package File2; sub setup { print "Setting up.\n"; } $::foo = 'bar'; # or define explicitely $File2::foo = 'bar'; 1; # use'd files have to return true!

Comment on Answer: How can I write and call subroutines in separate files?
Download Code
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (13)
As of 2015-07-06 11:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (73 votes), past polls