[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: What config file for a .pm perl module ?



On Fri, Dec 28, 2001 at 11:16:03AM -0600, Colin Watson wrote:
> 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.

Oh, OK. I always get confused between the orthographic of hashes and
references to hashes : %virtual={}; $virtual=""; $virtual={}; 

> 
> 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.

Well, that really depends on the context.

> 
>   * 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.
> 

I used it before and got this message too but since i didn't
understand it either, i quit the switch.

> In summary: your bug is that you need to change 'my %virtual1 = {};' to
> 'my $virtual1 = {};'.
> 

Thanks for your good explanation.

-- 
Eric VAN BUGGENHAUT     "Hay tampones y tampones..." (Eva Serrano)
			Andago
        \_|_/           Av. Santa Engracia, 54
       \/   \/          E-28010 Madrid - tfno:+34(91)2041100
a n d a g o  |--        http://www.andago.com
       /\___/\ 		"Innovando en Internet"
        / | \           eric@andago.com



Reply to: