in reply to Re: Global variables in Perl
in thread Global variables in Perl

Thanx monks! However, I had to include the 'our' or 'use var' statement (I believe the second one is deprecated now) so that Perl wouldn't croak a 'Global symbol "$DEBUG" requires explicit package name at...' error. If I remove 'use strict' AND the 'our'|'use var' statement I get the same 'Use of uninitialized value $DEBUG in print at...' message as before. Perhaps a bug with Exporter? I also tried Exporter-Lite without success...

Replies are listed 'Best First'.
Re^3: Global variables in Perl
by ikegami (Patriarch) on Jun 03, 2010 at 19:10 UTC

    I had to include the 'our' or 'use var' statement so that Perl wouldn't croak a 'Global symbol "$DEBUG" requires explicit package name at...' error.

    Not so.

    $ cat ConfigThisJunk.pm package ConfigThisJunk; use strict; use warnings; BEGIN { use Exporter; our @ISA = qw( Exporter ); our @EXPORT_OK = qw( $DEBUG ); } our $DEBUG = 1; 1; $ perl -wle'use strict; use ConfigThisJunk qw( $DEBUG ); print $DEBUG' 1

    I believe the second one is deprecated now

    Yeah, ignore that. They both have their uses. Think of it as "'our' is a better choice if both 'use vars' and 'our' fits your needs".