[Bioperl-l] Variable scope
Florin Iucha
florin at iucha.net
Mon Oct 2 20:47:01 UTC 2006
On Mon, Oct 02, 2006 at 07:43:13PM +0200, ende wrote:
> It is a annoying problem that is making me waste lot of time.
>
> I have a package with its new object, etc... and constants in it like:
>
> #-----
> use constant False => 0;
> use constant True => 1;
>
> our %CLRFG = (
> PLASMIDO => RED,
> POLY_A => GREEN,
> RESTR_SITES => BLUE,
> CONECTORS => MAGENTA,
> CONTAMINANTS => CYAN,
> );
>
> our %CLRBG = (
> PLASMIDO => "",
> POLY_A => "",
> RESTR_SITES => "",
> CONECTORS => "",
> CONTAMINANTS => "",
> );
> #------
>
> this constants are include with require "h.pl" from the main package
> file.
>
> I use this module from the mail command line driver to test it
> "using" it. In the command line driver I can use with no gripe the
> constants False and True directly, for example "return True", etc
> without any reference to the origin of that constant.
It is possible you get them from somewhere else.
> But, with respect to the variables (I would like they also were
> constants.. but how?), %CLRFG and %CLRBG I can't find the way of
> refering those int the module. Finally I have desisted and _copy_
> the definitions where I have needed it (in the sub were I print Ansi
> terminal colouring seqs...). I don't find how to refer those
> variables out of the module.
>
> I have tried %modulename::CLRFG, for example, but Perl gives me errors.
Did you actually declare a package name in "h.pl" ?
Is there any reason you don't call the file ".pm" and load it with
"use"? I have attached a small example of importing that works.
florin
--
If we wish to count lines of code, we should not regard them as lines
produced but as lines spent. -- Edsger Dijkstra
-------------- next part --------------
A non-text attachment was scrubbed...
Name: one.pm
Type: text/x-perl
Size: 118 bytes
Desc: not available
URL: <http://lists.open-bio.org/pipermail/bioperl-l/attachments/20061002/cf339845/attachment-0012.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: two.pl
Type: text/x-perl
Size: 69 bytes
Desc: not available
URL: <http://lists.open-bio.org/pipermail/bioperl-l/attachments/20061002/cf339845/attachment-0013.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.open-bio.org/pipermail/bioperl-l/attachments/20061002/cf339845/attachment.sig>
More information about the Bioperl-l
mailing list