in reply to Re: hash parameter question
in thread hash parameter question

That's exactly what's wrong
my %user=$_;
should be
my %user=%$_;
because $_ contains a *reference* to the nested hash. The fact that a scalar is being assigned to a hash is a sure sign something is wonky.

Replies are listed 'Best First'.
Re^3: hash parameter question
by jarich (Curate) on Dec 13, 2005 at 02:43 UTC

    Nope. $_ contains a string. A key from %users; which is presumably a username. Your suggestion will therefore not work.

    Had PerlHeathen written:

    foreach(values %users) { my %user=$_; my $pw=getpwnam($user{uname}); my $homedir=$pw->dir; }

    (note the use of values) then $_ would be a reference to a hash and then your solution would make the code work.

    For example:

    foreach(values %users) { my %user=%$_; my $pw=getpwnam($user{uname}); my $homedir=$pw->dir; }

    It is likely that this is what PerlHeathen was trying to write in the first place.

    jarich

      Thank you all. This is what I was looking for; I need both suggestions -- pass by reference & use values(%users) instead.

      thanks again!