Re: perl intersect problem



On Jan 22, 2008 9:31 PM, Chas. Owens <chas.owens@xxxxxxxxx> wrote:

Off hand I think that would only happen if the user name or the uid
was the same for some of your users. Can you present a cleaned up
version of your data the exhibits the problem? Also, You might want
to rewrite your loop more compactly and avoid duplicate calls to

Thanks for the code. I used it but have some problems, it prints
GLOB(0x9de5ce4) about 1000 times all in one line.
Shouldn't my code keep one of the duplicate users instead of taking
them both out?

split:

Warning, the following code is untested

#this function does not sort anything so Sort is a bad name
#also Perl functions don't normally have uppercase letters
sub make_passwd_unique {
my ($infile, $outfile) = @_;

#$out and $in are only scoped to this function, there is no need
for the tmp_ prefix
#also, it is handy to print the name of the file that errored
open my $out, '>', "$outfile"
or die "could not write to $out: $!";

open my $in, '<', "$infile"
or die "could not open $infile to sort: $!";

#declare variables close to where they are used, not at the top
my @unique;
my %seen;
while (<$in>) {
#skip comments and blank lines
next if /^#/ || /^\s*$/; #the m is only needed if you
are using a delimiter other than /
my ($uname, $uid) = (split /:/)[0,2]; #use a slice
instead of calling split twice (hey that rhymed!)
#if uid was seen then the uname would never be marked as seen
#this may not be a bug, but if so it should be
documented and you should revert to your old code
$seen{ $uid }++;
$seen{ $uname }++;
next if $seen{uid} > 1 || $seen{$uname} > 1;
print $out; #why save the data and then print it? Print as you go
}
print "DEBUG: Finishing make_passwd_unique function.\n" if $DEBUG;
}




--
This e-mail address is not monitored so please do not send me anything
important here. Thanks.
.



Relevant Pages

  • Re: perl intersect problem
    ... the output password file. ... sub Sort { ... next if $seen{$uid}++; ... instead of calling split twice ...
    (perl.beginners)
  • Re: perl intersect problem
    ... the output password file. ... disappearance but always the same few users are filtering. ... In the Unix password file format the user name has to be unique however the UID need not be so it is possible that two or more users have the same UID. ... sub Sort { ...
    (perl.beginners)
  • Re: Migrating me from linux/bsd to zOS
    ... I assume "uid" is schematic, ... The JCL example does nothing of the sort. ... For IBM-MAIN subscribe / signoff / archive access instructions, ... send email to listserv@xxxxxxxxxxx with the message: GET IBM-MAIN INFO ...
    (bit.listserv.ibm-main)
  • Re: commit 7e92b4fc34 - x86, serial: convert legacy COM ports to platform devices - broke my
    ... But maybe we could change PNPACPI to sort by them if ... It should sort devices with the ... because my devices are already ordered by _UID by default. ...
    (Linux-Kernel)