Hi,
I have a very strange problem (to me anyways). I have the following
subroutine to sort unique a UNIX password file based on UID and
username. But the problem is that some of the users get disappeared
the output password file. I couldn't figure out the pattern of user
disappearance but always the same few users are filtering.
Can someone please take a look at my code and tell me why is it
messing with me? Any suggestion to rewrite it is also welcome. Thank
you all.
sub Sort {
my ($infile,$outfile) = @_;
my @unique = ();
my %seen = ();
open my $tmp_out, '>', "$outfile"
or die "could not write the sorted list: $!";
open my $tmp_in, '<', "$infile"
or die "could not open $infile to sort: $!";
while (<$tmp_in>) {
next if (m/^#/); # Skip comments
next if (m/^\s*$/); # Skip blank lines
my $uname = (split /:/)[0]; # username
my $uid = (split /:/)[2]; # uid
next if $seen{ $uid }++;
next if $seen{ $uname }++;
push @unique, $_;
}
print $tmp_out @unique;
print "DEBUG: Finishing Sort function.\n" if $DEBUG;
}
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/