Re: What config file for a .pm perl module ?
On Fri, Dec 28, 2001 at 03:02:29PM +0100, Eric Van Buggenhaut wrote:
> my %virtual1 = {};
[...]
> $virtual1->{$user[0]}->{$fields[$_]} = $user[$_];
[...]
> When running the script using this module, I get this error:
>
> mrmime_SLASH:/# install-slashsite
> Global symbol "$virtual1" requires explicit package name at /usr/lib/perl5/DBIx/Password.pm line 47.
>
> What does it mean ??
You've created the lexical variable %virtual1. Once you've done that,
$virtual1{foo} is OK - that accesses elements of the hash.
$virtual1->{foo} is something different, though. That takes $virtual1,
treats it as a reference to a hash, and tries to access elements within
that hash. You haven't declared $virtual1 as a lexical, so, since you
have strict vars in force, perl correctly complains that you're using an
undeclared package variable.
The important things to understand are:
* $virtual1 is *not* the same as %virtual1. In particular, it occupies
a different slot in the symbol table, and declaring one as a lexical
doesn't affect the other. Don't get confused by the syntax for
accessing elements of hashes [1].
* {} returns a reference to a hash, not the hash itself.
* Always, always, always use -w (or 'use warnings' in Perl >= 5.6). If
you'd done this, you'd get the warning "Reference found where
even-sized list expected", which points to the real problem.
In summary: your bug is that you need to change 'my %virtual1 = {};' to
'my $virtual1 = {};'.
[1] Incidentally, this is slated to change in Perl 6 to something closer
to what a lot of people seem to expect. See
<URL:http://www.perl.com/pub/a/2001/05/03/wall.html>.
--
Colin Watson [cjwatson@flatline.org.uk]
Reply to: