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

Re: use, require, do or what?

by massa (Hermit)
on Jul 30, 2008 at 18:57 UTC ( [id://701234]=note: print w/replies, xml ) Need Help??


in reply to use, require, do or what?

Just two suggestions:
  1. Don't use loose .pl files. Make proper modules, with their own namespaces. perlmod is your friend.
  2. Don't make assignment to variables inside your modules. Return the value of the calculation from a function, and use that.
What you have will be something like:
use strict; package Module1; use Exporter 'import'; our @EXPORT_OK = qw(compute_value); sub compute_value { # do the computation } 1; # this is required, see perldoc perlmod
in the file "Module1.pm" and something like:
use strict; use Module1; my $variable1 = Module1::compute_value();
or:
use strict; use Module1 qw(compute_value); my $variable1 = compute_value();
in your main script.
[]s, HTH, Massa (κς,πμ,πλ)

Replies are listed 'Best First'.
Re^2: use, require, do or what?
by AKSHUN (Novice) on Jul 30, 2008 at 19:04 UTC
    Creating a proper module isn't an option. I have to work within the constraints of my employer's dev environment.

    The whole purpose of the code is to assign values to variables. I over-simplified in my examples.

    Basically, the code is to take ARGV and convert it into a date, and if there is no ARGV it creates the date based upon localtime.
      Could you please explain to me exactly _how_ your employer's dev env precludes you from making proper modules and subroutines instead of loose .pl files? Modules can be put in the current dir, just like your .pl file in your example...
      []s, HTH, Massa (κς,πμ,πλ)
        We only use modules that are a part of the core distribution of Perl.
      Wait, so then why are you trying to put the variables in another file?
      -Actualize
      A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2024-04-24 22:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found