Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re: find common data in multiple files

by Dallaylaen (Hermit)
on Dec 28, 2017 at 16:01 UTC ( #1206333=note: print w/replies, xml ) Need Help??

in reply to find common data in multiple files

#!perl use strict; use warnings; # The final hash my %all; # process files one by one, gather lines from each foreach (@ARGV) { my $hash = unique_in_file($_); $all{$_}++ for keys %$hash; }; # print result print "$_\n" for grep { $all{$_} == @ARGV; # don't hardcode the needed count, the number +of files *will* change } sort keys %all; sub unique_in_file { my $fname = shift; # don't bother opening local @ARGV = ($fname); # do the same uniq(1) but for the current file my %uniq; while (<>) { chomp; # preprocess line here $uniq{$_}++; }; # could've returned array as well return \%uniq; };

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1206333]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2018-02-25 04:39 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (312 votes). Check out past polls.