in reply to Re: match two files
in thread match two files

Here is simple solution:

#!/usr/bin/perl my @tmp1 = map { chomp; [ split /\s+/, $_, -1 ] } `cat tmp01`; # (*) my %tmp2 = map { chomp; my @a = split /\s+/, $_, -1; ($a[0], \@a) } `cat tmp02`; print join "\t" @$_, @{ $tmp2{$$_[0]} }, "\n" for @tmp1; # (*) instead of `cat tmp01` it is more safe to: #use Path::Tiny; #path("tmp01")->lines_utf8({chomp => 1});

Congratulations, you have won not just one, but two Useless Use of Cat Awards!

Further more, you have prepared two shell injection vulnerabilities (The problem of "the" default shell), you artifically restricted the "solution" to Unix systems (Windows and many other systems have no cat), and you are limiting the sum of the input file sizes to significantly less than available RAM and swap by not reading line-by-line, but instead reading both input files all at once.

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)