Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

! exists in my hash. want to see all that dont exist.

by dbs (Sexton)
on Apr 20, 2011 at 20:27 UTC ( #900418=perlquestion: print w/replies, xml ) Need Help??

dbs has asked for the wisdom of the Perl Monks concerning the following question:

I want to print out all the keys through my loop that dont exist in my hash NgrpsHash, but its only printing one of them, cbtest.
use strict; use warnings; my $notexists = 0; my $hashdiff = ( (scalar keys %EgrpsHash) - (scalar keys %NgrpsHash) +); print "\nI am now checking primary and secondary groups defined in AD +and locally on $host...\n"; LABEL: for my $ekey (keys %EgrpsHash) { last if $notexists >= $hashdiff; if ( ! exists $NgrpsHash{$ekey} ) { print uc("\n$nuser is **not** in the same 'ad' and or 'local' +groups as $euser is!\n\n"); print uc("*** $nuser needs to be in ''$ekey'' group(s) for int +erface support rights! ***\n\n"); print "Please correct this then rerun with the -r flag!\n\n"; print "$nuser\'s AD+local groups\n", join("\n", sort keys %Ngr +psHash),"\n"; print '=' x 11,"\n"; print "$euser\'s AD+local groups\n", join("\n", sort keys %Egr +psHash),"\n\n"; print uc("please change this within centrify gui! right-click +on new user, properties, profile tab, primary group, then rerun \n\n" +); ++$notexists; goto LABEL; } }
__DATA__ is tsilvia's AD+local groups cbpro_group cbproop cbqa cbqaop cbtestop =========== thendri1's AD+local groups cbpro cbpro_group cbproop cbqa cbqaop cbtest cbtestop
thx!

Replies are listed 'Best First'.
Re: ! exists in my hash. want to see all that dont exist.
by chromatic (Archbishop) on Apr 20, 2011 at 20:33 UTC

    I prefer something like:

    my @difference = grep { not exists $NgrpsHash{ $_ } } keys %EgrpsHash;
Re: ! exists in my hash. want to see all that dont exist.
by JavaFan (Canon) on Apr 20, 2011 at 21:23 UTC
    What's the purpose of your goto LABEL;?

    Also, if %EgrpsHash contains one more element than %NgrpsHash, then the last if $notexists >= $hashdiff; bails out of the loop after finding a difference.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://900418]
Approved by ikegami
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (8)
As of 2021-04-23 11:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?