Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Reconcile one list against another

by jpl (Monk)
on May 04, 2011 at 18:23 UTC ( #902961=note: print w/replies, xml ) Need Help??


in reply to Reconcile one list against another

Your life will improve measurably if you make users a hash instead of an array.

Not to discourage anyone from using perl, but you can probably do this as well with cut, sort and comm.

Replies are listed 'Best First'.
Re^2: Reconcile one list against another
by spartan (Pilgrim) on May 04, 2011 at 18:40 UTC
    Holy mackerel... So, if I make each line a hash key, and iterate over users I should increment hash value for each time I get a user match against the line.

    Then just print out the hash for keys that are zero, or greater than one, depending on whether or not I want to see a list of users that do no match, or do match respectively!

    I think that will work. Stay tuned for code...

    Very funny Scotty... Now PLEASE beam down my PANTS!

      Here's a simple way to take the difference of sets.
      use Data::Dumper; %one = ( 'a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5, 'f' => 6,); %two = ( 'a' => -1, 'e' => -2, 'i' => -3, 'o' => -4, 'u' => -5,); print Dumper(\%one, \%two); %tmp = %one; delete @tmp{keys %two}; print Dumper(\%tmp); %tmp = %two; delete @tmp{keys %one}; print Dumper(\%tmp);
      Running the above produces the following:
      $VAR1 = { 'e' => 5, 'c' => 3, 'a' => 1, 'b' => 2, 'd' => 4, 'f' => 6 }; $VAR2 = { 'e' => -2, 'u' => -5, 'a' => -1, 'o' => -4, 'i' => -3 }; $VAR1 = { 'c' => 3, 'b' => 2, 'd' => 4, 'f' => 6 }; $VAR1 = { 'u' => -5, 'i' => -3, 'o' => -4 };
Re^2: Reconcile one list against another
by jaredor (Priest) on May 05, 2011 at 06:52 UTC

    Ditto! However, instead of comm, I tend to use uniq in a pipeline.

    cat ${file1} ${file2} ${file2} | cut -d: -f1 | sort | uniq -u

    (Slacking off and just doing the easier case for user id in the first field as opposed to the harder case of name extraction from the fifth field.)

    Translating this to perl comes up with something like what's given in the following answers, but I find it's handy to test the rough idea on the command line if possible.

    (EDIT: Removed the accidental dot between the paragraph and code tags. Moral: don't do markup after midnight.)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://902961]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2023-03-24 18:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which type of climate do you prefer to live in?






    Results (61 votes). Check out past polls.

    Notices?