linux - Comparing and displaying hash values -
i able print of lines /etc/passwd
uid
, username.
i compare values of uid
, display corresponding usernames <150
, >150
.
this while loop , count
while(<passwd>){ chomp; @f = split /:/; sort @f; @{$passwd{$f[3]}}=@f; print @f[3 , 0], "\n"; } $count = keys(%passwd); print $count, "\n";
sort @f
nothing - sort
returns list sorted, not change in place. if added use warnings;
programme, perl tell you.
this how it:
#!/usr/bin/perl use warnings; use strict; open $passwd, '<', '/etc/passwd' or die $!; %passwd; while (<$passwd>) { chomp; @f = split /:/; @{ $passwd{ $f[3] } } = @f; } $reported = 0; $k (sort { $a <=> $b } keys %passwd) { if ($k > 150 , not $reported) { $reported = print "over 150\n"; } print "$k\n"; }
you can grep
keys small ones:
my @under150 = grep $_ < 150, keys %passwd; print $_->[0], "\n" @passwd{ @under150 };
Comments
Post a Comment