in reply to Compare csv file fields?

Good god, man! Think a little bit. This is a standard ETL action.
my %passwd; my %smbpasswd; while (<PASSWD>) { next if /^#/; chomp; my ($name, $uid) = (split ':', $_, 4)[0,2]; $passwd{$uid} = $name; } # Do the same for SMBPASSWD, except use [0,1] instead of [0,2] foreach my $uid (keys %passwd) { unless (exists $smbpasswd($uid}) { print "'$uid' in passwd, not in smbpasswd\n"; next; } # Deleted to do later comparison my $smb_name = delete $smbpasswd{$uid}; unless ($passwd{$uid} eq $smb_name) { print "$uid has $passwd{$uid} in passwd, but $smb_name in smbb +passwd\n"; } } while (my ($k, $v) = each %smbpasswd) { print "$k in smbpasswd, not in passwd\n"; }

------
We are the carpenters and bricklayers of the Information Age.

The idea is a little like C++ templates, except not quite so brain-meltingly complicated. -- TheDamian, Exegesis 6

Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

Replies are listed 'Best First'.
Re: Re: Compare csv file fields?
by traveler (Parson) on Oct 07, 2003 at 17:21 UTC
    Yes, dragonchild this is indeed the usual way. That's why I said it's what I had considered. What I am looking to see is whether that is the only reasonable (or practical) way or whether there is another, better, way using some technique I did not know or using some module(s) I had not found.
      Parsing can be done using tilly's Text::xSV. Array::Compare might be useful in building the comparisons, as might Set::Scalar. Set::Scalar will allow you to generate two lists of UIDs and get the differences between the two. Then, you can do the same thing, but with the names from the acceptable UIDs.

      Personally, I think that all these modules are overkill for what is, essentially, a one-off. But, that's just me. (Do you really anticipate your *passwd files getting out of sync again?? That sounds like a bigger issue, to me ...)

      ------
      We are the carpenters and bricklayers of the Information Age.

      The idea is a little like C++ templates, except not quite so brain-meltingly complicated. -- TheDamian, Exegesis 6

      Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.