On 16 May 2000 11:06:13 -0400, [EMAIL PROTECTED] (David S. Rosinger)
wrote:

>Jan, this is leading me into some questions on style. Let's take the
>following for example from build 522:
>
>    d:/Perl/bin/ppm.pl

Please don't use the ppm source code as a base for stylistic wisdom;  some
of the code in there is still from the days when the author was learning
Perl.

>The following lexical variable has *file scope*:
>
>    my %options = PPM::GetPPMOptions();
>
>Then several variables are made *global*:
>
>    use vars qw ($location $Ignorecase $clean
>      $confirm $force_install $root $build_dir $more
>      $trace $tracefile $verbose);
>
>and set with *typeglob* notation:
>
>    *Ignorecase = \$options{'IGNORECASE'};
>
>Question #1: What is the point of using a typeglob here?

This is aliasing $Ignorecase and $options{IGNORECASE}.  They now point to
the same variable;  changing one will also change the other (because they
are the same).

>And from:
>
>    What's New in Perl 5.6.0?
>
>      http://www.perl.com/pub/2000/04/whatsnew.html
>
>      | `our' Variables
>      |
>      | Whereas `my' declares lexical variables, `our' declares global
>      | variables - it's a cleaner and hopefully more intuitive
>      | replacement for `use vars'.
>
>Question #2: Is `our' merely syntactic sugar, or does it change the
>behavior of global variables in some way? Does it behave differently
>at compile time than `use vars'?

"our" is lexically scoped:

    if ($cond) {
        our $var = 42;
    }
    print $var;  # will create an error under "use strict"

The "use vars" stuff is visible throughout the rest of the compilation
unit.  With "our" you can define dynamic variables just within a lexical
scope (yes, a confusing concept;  you have to differentiate between
lexical visibility and dynamic lifetime).

Another property to watch out for is that "our" works across package
"boundaries", just like "my":

    package Foo;
    our $x = 42;
    print $x; # prints $Foo::x

    package Bar;
    print $x; # still prints $Foo::x

    our $x;
    print $x; # now prints $Bar::x

-Jan

---
You are currently subscribed to perl-win32-users as: [archive@jab.org]
To unsubscribe, forward this message to
         [EMAIL PROTECTED]
For non-automated Mailing List support, send email to  
         [EMAIL PROTECTED]

Reply via email to