in reply to Ugly ways to declare global variables?

For something extra-ugly, you can do the same thing vars does without using the module (and you don't even need my!).
use strict; BEGIN { package vars; no strict qw(refs); $a="main::x"; *$a = \$$a } $x = 5; print $x;

Replies are listed 'Best First'.
Re^2: Ugly ways to declare global variables?
by Roy Johnson (Monsignor) on Apr 25, 2005 at 20:02 UTC
    More simply, since we don't need to pass names around as strings:
    use strict; use warnings; BEGIN { package vars; *::x = \$::x } $x = 5; print $x;

    Caution: Contents may have been coded under pressure.
      Thanks, good point. What happened was that I based my example too literaly in the vars.pm code, where the variable names are indeed passed around as strings.