[Developers] Perl modules and global variables
Erik Schnetter
schnetter at cct.lsu.edu
Tue Feb 6 21:34:01 CST 2007
On Feb 6, 2007, at 18:19:13, Carsten Schneemann wrote:
> Hi!
>
> Erik Schnetter wrote:
>> I've tried to introduce a "use strict" to the file
>> interface_parser.pl. One problem is that this file accesses the
>> global variable $cctk_home, which is defined in CST before it
>> requires
>> interface_parser.pl.
>>
>> How do I propagate the variable $cctk_home from CST to
>> interface_parser.pl?
>>
> My Perl knowledge is limited, but AFAIK unless you the required file
> contains a "package" (which is roughly similar to a Fortran module),
> which interface_parser.pl doesn't, the global variables from CST *are*
> in fact visible in / propagated to interface_parser.pl. The problem
> here
> is rather that with "use strict" you must either explicitly declare
> $cctk_home and friends as global in CST (via "our $cctk_home") *or*
> you
> have to use the fully qualified name $main::cctk_home when referencing
> them (instead of the "lazy" form $cctk_home).
>
> So one solution would be to declare all global variables in CST as
> global or replace all references to global variables in
> interface_parser.pl by their fully qualified names. Since both options
> are somewhat messy you could try to define a lexical variable with the
> same name as an alias in interface_parser.pl, e.g.
> my $cctk_home = $main::cctk_home
> and similarly for each global variable it uses.
>
> There might also be more sophisticated solutions...
Declaring all global variables in CST would not have been that bad.
But declaring them with "our" doesn't make them visible in required
files. I then opted to use $main::cctk_home, which works fine.
Thanks Larry,
-erik
--
Erik Schnetter <schnetter at cct.lsu.edu>
My email is as private as my paper mail. I therefore support encrypting
and signing email messages. Get my PGP key from www.keyserver.net.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 186 bytes
Desc: This is a digitally signed message part
Url : http://www.cactuscode.org/pipermail/developers/attachments/20070206/bcb272d8/attachment.bin
More information about the Developers
mailing list