When you actually declare a variable, it's really new. It's fresh and unused from that point.

I'm having a hard time getting your point. Even if a declared variable starts out as "fresh and unused", the fact that it can be modified from anywhere else outside the package implies that this guarantee is meaningful only in very limited cases. An example will clarify what I mean:

# in Foo.pm package Foo; use strict; use warnings; use vars qw( $foo $bar ); $bar = 2; our $baz; sub print_out { ++$foo; ++$bar; ++$baz; print "\$foo: $foo\n\$bar: $bar\n\$baz: $baz\n"; } 1; # in foo.pl use strict; use warnings; package Foo; $Foo::foo = 7; $Foo::bar = 5; $Foo::baz = 8; package main; use Foo; Foo::print_out(); __END__ % perl foo.pl $foo: 8 $bar: 6 $baz: 9
It is true that, contrary to $baz, $foo and $bar are guaranteed to "start out" as being unused. Nonetheless, by the time they are actually used (e.g. in subs like print_out()) they has been modified from outside the package. So most of the code that uses $foo and $bar has no more assurance as to the purity of these variables than code that uses $baz has about its purity. Therefore, the fact that $foo and $bar start out in a pristine state strikes me as somewhat academic. So wonder if I am just missing some major aspect of the problem.


In reply to Re^4: Ugly ways to declare global variables? by tlm
in thread Ugly ways to declare global variables? by wolfger

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.