Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: using "require" problem

by Discipulus (Canon)
on Sep 26, 2017 at 07:58 UTC ( [id://1200090]=note: print w/replies, xml ) Need Help??


in reply to using "require" problem

Hello gauss76,

Normally you will put your routines into a module: Routines.pm will be the name of the file with inside a package called Routines You can use Exporter to export, possibly just on demand, one or more subs.

Consider also that current directory . is no more included in @INC in newer Perl version for security reasons: you can include it with use lib '.'; (or adding it directly to @INC or using the -I perl switch) PS this is probably unrelated (see below) but important to know anyway

Look at my homenode for many links about modules and code reuse: especially require "shared.pl" with use strict; and Include subs from different perl file

L*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Replies are listed 'Best First'.
Re^2: using "require" problem
by haukex (Archbishop) on Sep 26, 2017 at 08:03 UTC
    Consider also that current directory . is no more included in @INC in newer Perl version for security reasons: you can include it with use lib '.'

    While correct, the way I understood the question is that the working directory is changing, so I don't think that would help here - but this pattern would, which I've used many times:

    use FindBin; use lib $FindBin::Bin; use Routines;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (3)
As of 2024-04-20 13:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found