Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Code does work in different packages only

Reply
Thread Tools

Code does work in different packages only

 
 
Ferry Bolhar
Guest
Posts: n/a
 
      06-25-2006
Hi folks,

While looking at the code in vars.pm (the "use vars" pragma), I tried to
reproduce its behaviour:

use strict;
use vars $x;
$x = 3;

by writing:

use strict;
BEGIN {
*main: = \$main:;
}
$x = 3;

instead. However, this code doesnt work, I get the messages

Variable "$x" not imported at line 5
Global symbol "$x" requires explicit package name at line 5

(Line 5 contains the assignment to scalar $x)

However, when including a "package hugo;" in the BEGIN block (or even
outside, and a "package main;" thereafter), the code works as expected. It
also works when the BEGIN block runs in package "main" and the scalar
assignment in a different package. It fails, whenever both assignments
(typeglob and scalar) are executed in the same package.

Can someone explain why? The typeglob assignment occurs full-qualified, so
it shouldn't matter which package is currently active. However, it does.
Why?

Thanks for your answers and kind greetings from Vienna,

Ferry


 
Reply With Quote
 
 
 
 
Anno Siegel
Guest
Posts: n/a
 
      06-25-2006
Ferry Bolhar <(E-Mail Removed)> wrote in comp.lang.perl.misc:
>Hi folks,
>
>While looking at the code in vars.pm (the "use vars" pragma), I tried to
>reproduce its behaviour:
>
>use strict;
>use vars $x;
>$x = 3;
>
>by writing:
>
>use strict;
>BEGIN {
> *main: = \$main:;
>}
>$x = 3;
>
>instead. However, this code doesnt work, I get the messages
>
>Variable "$x" not imported at line 5
>Global symbol "$x" requires explicit package name at line 5
>
>(Line 5 contains the assignment to scalar $x)
>
>However, when including a "package hugo;" in the BEGIN block (or even
>outside, and a "package main;" thereafter), the code works as expected. It
>also works when the BEGIN block runs in package "main" and the scalar
>assignment in a different package. It fails, whenever both assignments
>(typeglob and scalar) are executed in the same package.
>
>Can someone explain why? The typeglob assignment occurs full-qualified, so
>it shouldn't matter which package is currently active. However, it does.
>Why?


That's a documented fact. Unfortunately I forget where exactly it is
documented, but an assignment to a typeglob only counts as importation
when if happens in a package that is different from the typeglob's.

Anno
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Python Packages : A loomingproblem? packages might no longer work? (well not on your platform or python version anyway) David Lyon Python 19 04-23-2009 11:10 PM
How to link different site-packages to different Python? Davy Python 2 11-10-2007 06:19 AM
Advice on converting hashed packages to pseudo-hashed packages Ian Perl Misc 3 02-12-2005 12:17 AM
Do the javax.imageio packages replace packages in com.sun.image? Paul Smith Java 0 11-18-2003 02:58 PM



Advertisments