in reply to SCALAR output instead of attribute name.

I think you are slightly confused about references. Taking the reference of a variable does not return its name (although this is a clever idea). Is this why you expect @attrs to contain qw(nam pwd uid ..)?

The name of a variable can be used as a "soft reference" (only when the referent is a symbol table variable and only when in no strict 'refs'). But think of it, not all scalar values even have names, and some have many! Because of this, taking a reference to any variable using the backslash operator creates a special "hard reference" scalar. When you print out something of this reference type, you get SCALAR(0x81717c4) (if the referent is a normal scalar). Perhaps consult perlreftut for more detailed info?

A better way to fill your hash the way you want is like this:

my @fields = qw/nam pwd uid gid dsc hom shl/; while (<F>) { my %attrs; @attrs{@fields} = split /:/, $_; $password->{ $attrs{nam} } = \%attrs; }
Again, you'll need an explicit list of keys for the hash, as you can't extract the attribute names from the variables.

blokhead

Replies are listed 'Best First'.
Re: Re: SCALAR output instead of attribute name.
by sschneid (Deacon) on Dec 18, 2003 at 18:41 UTC
    Fantastic. Thanks a bunch.

    -s.