Beefy Boxes and Bandwidth Generously Provided by pair Networks DiBona
go ahead... be a heretic
 
PerlMonks  

Re: hash parameter question

by chas (Priest)
on Dec 12, 2005 at 17:57 UTC ( [id://516170]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to hash parameter question

I'm not familiar with User::pwent. However, your find_deletion_candidates sub doesn't make much sense to me. The keys of %users are usernames , so what are %user and $user{uname}?
(Update: I guess you got several answers while I was looking at your code...)

Replies are listed 'Best First'.
Re^2: hash parameter question
by ikegami (Patriarch) on Dec 12, 2005 at 18:09 UTC

    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.

      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!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://516170]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.