--- Rodrick Brown <[EMAIL PROTECTED]> wrote: > Is there a more efficient way to handle the method I > choose to unroll my HoH. > Thanks. > > #!/usr/bin/perl -w > use strict; > use warnings; > use Data::Dumper; > > my @data = <STDIN>; > > my ($user,$gid,$homedir,%userMap); > foreach(@data) { > /^#/ and next; > /(\w+):/ and $user = $1; > /\w+:*:(\d+):/ and $gid = $1; > /.*:(.*)$/ and $homedir = $1; > $userMap{$homedir}->{$user} = $gid; > } > > #print Dumper(\%userMap); > > while(my ($k0,$h0) = each(%userMap)) { > foreach my $shell ($k0) { > print $shell,"\n"; > print "--------------\n"; > while(my ($k1,$v0) = each(%$h0)) { > print "$k1 $v0\n"; > } > print "\n"; > } > #print $k,"\n\t",$_,"\n" foreach(values %$v); > } >
Hello, Just give my version.It does the same work and seems more clear. use strict; use warnings; my %hash; open FD,'/etc/passwd' or die $!; while(<FD>) { chomp; my ($user,$uid,$shell) = (split/:/)[0,2,6]; $shell ||= 'null'; push @{$hash{$shell}},[$user,$uid]; } close FD; for my $s (keys %hash) { print "\n$s\n--------\n"; for my $p (@{$hash{$s}}) { print "@$p\n"; } } __END__ HTH. ____________________________________________________________________________________ Moody friends. Drama queens. Your life? Nope! - their life, your story. Play Sims Stories at Yahoo! Games. http://sims.yahoo.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/