Re: Iterating thru array of hashes

Graham Barr <[email protected]>
Newsgroups gmane.comp.lang.perl.modules.ldap
Message-ID <[email protected]>
On Mar 31, 2010, at 10:31 PM, Prashanth Sundaram wrote:
> 
> 
> sub create_user {
>    my(@add_user)=@_;
>    print Dumper(@add_user);
>    for $eachuser (@add_user)
>    {   print "\n==========\n ";
>        #for $attribut (keys %eachuser)
>        #{  
>        #   if ($attribut eq "\n objectClass"){ for (my $j=0; $j < 12;
> $j++){print " objectClass:".$eachuser->{$attribut}[$j]; } }
>        #   print $attribut.":".$eachuser->{$attribut}."\n";
>        #}
>        $dn_add='uid='.$eachuser->{'uid'}.',ou=people,'.$ldap_base;
>        print "dn: $dn_add \n";
>        $new_entry = Net::LDAP::Entry->new;
>        $new_entry->dn($dn_add);
>        $new_entry->add($dn_add,attr => [ %eachuser ]);

I would really suggest you add

use strict;

to the start of your script as there is no such variable %eachuser, you need %$eachuser

Graham.

>        my $mesg_ld = $new_entry->update($ldap_ld);
>        if ($mesg_ld->code)
>        { 
>          logit('err',"Error adding uid:".$eachuser->{'uid'}."with
> uidNumber:".$eachuser->{'uidNumber'},$mesg_ld);
>        }
>        else
>        { 
>          logit('info',"Successfully added
> uid:".$eachuser->{'uid'}."uidNumber:".$eachuser->{'uidNumber'},$mesg_ld);
>        }
>    }
> }
> 
> 
> 
> 
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.