Here's one for you. I am hoping someone can criticize this or suggest some better way
of writing parts of this code.
Regards
I.S
#!/usr/bin/perl -w
use strict;
my $pass1 = "./passwd";
my $pass2 = "./passwd.old";
open PASS1 , "< $pass1" or die "Error opening $pass1: $!\n";;
open PASS2 , "< $pass2" or die "Error opening $pass2: $!\n";;
my %passfile1;
my %passfile2;
while (<PASS1>) {
chomp;
my @passline1 = split(":",$_);
# read file into a hash
my $ids = $passline1[0];
$passfile1{$ids} = \@passline1;
}
while (<PASS2>) {
#same as above
chomp;
my @passline2 = split(":",$_);
# read file into a hash
my $ids = $passline2[0];
$passfile2{$ids} = \@passline2;
}
foreach my $ids (keys %passfile1) {
my @l1 = @{$passfile1{$ids}};
if (exists $passfile2{$ids}) {
my @l2 = @{$passfile2{$ids}};
my $compare = compare_arrays(\@l1,\@l2);
if ($compare == 1) {
my $line = join ':', @l1;
print "$line\n";
next; }
#lines from second file
my $line = join ':', @l2;
print "$line\n";
}
#lines from first file
my $line = join ':', @l1;
print "$line\n";
}
foreach my $ids (keys %passfile2) {
my @l1 = @{$passfile2{$ids}};
if (!exists $passfile1{$ids}) {
my $line = join ':', @l1;
print "$line\n";
}
}
sub compare_arrays {
my ($first, $second) = @_;
local $^W = 0;
return 0 unless @$first == @$second;
for (my $i = 0; $i < @$first; $i++) {
return 0 if $first->[$i] ne $second->[$i];
}
return 1;
}
_END_
John_Kennedy <[EMAIL PROTECTED]> wrote:
>Hello all,
>I am trying to write a script that will combine 2 /etc/passwd files.
>The tricky part is that most of the entries from passwd1 are already in
>passwd 2 but some have errors. (some of the password fields are locked,
>some of the group ids are wrong)
>Does anyone have a script (or know of one) that combines 2 passwd files
>that I can get a start from?
>Thanks,
>John
>
>
>--
>"I fear all we have done is to awaken the sleeping giant and fill
>him with terrible resolve"
>- Japanese Adm. Isoroku Yamamoto after the attack on Pearl Harbor
>
>--
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
>
>
__________________________________________________________________
Your favorite stores, helpful shopping tools and great gift ideas. Experience the
convenience of buying online with Shop@Netscape! http://shopnow.netscape.com/
Get your own FREE, personal Netscape Mail account today at http://webmail.netscape.com/
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]