[PLUG-Devel] Perl Question: Sourcing variables?
daniel at wolstenholme.net
daniel at wolstenholme.net
Thu Oct 25 22:09:17 MST 2007
If you absolutely must share variables between different Perl scripts, I think
you'd probably do it the same way: just use environment variables. To access
env variables in Perl, refer to them as "$ENV{ENVVARNAME}" (I think, my Perl is
a little rusty). Another way, if there's lots of them, or you'd prefer to not
waste environment space on program-specific variables, is to place them into a
separate Perl file ("module"), and include that file with "use". You can read
about this by typing "perldoc -f use" at the command line.
However, the best thing to do, in my opinion, is to go back and see why you
have architected things this way to begin with; do you really need to share
variables between different programs? Perhaps these different, disparate
programs could be rolled together into one larger program, if they're all
closely related and doing very similar things. You may find that, instead of
just variables, they could also share subroutines. Even if you insist on
having differently-named commands (instead of "programname -opt") to select the
different modes or functions, this is easy to do with one larger program by
symlinking all the commands to a single executable (like busybox does), and
then have your program check an environment variable to see what name it was
called with.
Dan
>----Original Message----
>Message: 1
>Date: Thu, 25 Oct 2007 11:54:50 -0700
>From: "Eric \"Shubes\"" <plug at shubes.net>
>Subject: [PLUG-Devel] Perl Question: Sourcing variables?
>To: plug-devel at lists.PLUG.phoenix.az.us
>Message-ID: <4720E67A.9030509 at shubes.net>
>Content-Type: text/plain; charset=UTF-8
>
>In an effort to polish my virtually non-existent Perl skills, I'm attempting
>to translate some bash scripts I have written into perl.
>
>The several bash scripts scripts share several environment variables, which
>are obtained by sourcing a separate bash script that sets the variables:
>. config-file
>
>In my searching this morning I haven't found a 'nice' way to do this in
>perl, so I figure I'd ask the experts. :) What is the 'preferred' way (or
>even a 'nice' way) of making common variables available to several different
>perl scripts?
>
>--
>-Eric 'shubes'
More information about the PLUG-devel
mailing list