In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] (Daniel Falkenberg) wrote:
> Hey all, > > Currently I am working on the Linux /etc/passwd file. Now I want to be > able to split the /etc/passwd file for example... > > tunnel:x:503:503::/home/tunnel:/bin/bash > test:x:504:50:Test Account:/home/test:/bin/false > test2:x:507:502:Test Account:/home/test2:/bin/false > daniel:x:508:45:Thats Me:/home/daniel:/bin/false > *test6:x:509:45:Test Account:/home/test6:/bin/false > > Now I have no trouble actually splitting the file but what I really want > to do is have all the values of $lines > > $file = '/etc/passwd'; > > open PASSWD, "$file" or die "$file: $!\n"; > while ($lines = <PASSWD>) { > @lines = split (/:/, $lines); > if ($lines[3] == 45 ) { > #Store all users and their gids in a hash! > $users{$lines[4]} = $lines[0]; > } > } > close PASSWD; > > foreach $fullnames (keys %users) { > print $fullnames, "\n"; > } > > foreach $usernames (values %users) { > print $usernames, "\n"; > } > > Why is it the hash doesn't insert all the keys and values. I get a > result that is complety wrong. Such as the following... > > %users = ( > 'Test Account' => 'test6' > ); > > This is about all I get. When we all know very well that the file > ($file) contains alot more users with a GID of 45. Can some one point > me into the right direction as to what I am doing wrong here? that's possibly because you're not using my try while (my $lines = <PASSWD>) { my @lines = split (/:/, $lines); foreach my $fullnames (keys %users) { print $fullnames, "\n"; } foreach my $usernames (values %users) { print $usernames, "\n"; } Make sure you have use strict; at the top of your program and it will help catch things like this. also I'd suggest using the username as the key and reversing the meaning of the above two foreach statements $users{$lines[0]} = $lines[4]; print pack "H*", "4a75737420416e6f74686572204d61635065726c204861636b65722c0d"; -- Scott R. Godin | e-mail : [EMAIL PROTECTED] Laughing Dragon Services | web : http://www.webdragon.net/ It is not necessary to cc: me via e-mail unless you mean to speak off-group. I read these via nntp.perl.org, so as to get the stuff OUT of my mailbox. :-) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]