sacked has asked for the wisdom of the Perl Monks concerning the following question:
And here is program.pl:#!/usr/local/bin/perl -w # use strict; use diagnostics; use vars qw( $qux $quo $zip ); $foo = 1; $bar = 2; $baz = 3; $qux = 4; $quo = 5; $zip = 6; sub hello { print "Hello, World!\n" }
In program.pl, when printing the symbol table, the identifiers for $qux, $quo, $zip appear in main's symbol table, but I can only access them by explicitly providing the package name. This throws a warning, however: Name "main::zip" used only once: possible typo at require.pl line 11 (same warning for $qux and $quo).#!/usr/local/bin/perl -w # use strict; use diagnostics; use vars qw( $foo $bar $baz ); require 'foobarbaz.pl'; # OK, but need package name for $qux, $quo, $zip print "$_\n" foreach( $foo, $bar, $baz, $::qux, $::quo, $::zip ); hello(); # fine #print $qux; ## XXX gives an error while (my ($k,$v) = each %:: ) { print $k . ":\t\t" . $v . "\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: use vars in a require()d file
by chromatic (Archbishop) on Mar 12, 2001 at 05:52 UTC | |
|
Re: use vars in a require()d file
by athomason (Curate) on Mar 12, 2001 at 05:58 UTC | |
by tilly (Archbishop) on Mar 12, 2001 at 07:58 UTC |