Hoping everyone had a great New Year and thanks for the replies. I started trying some more tactics to find out how to compare columns and lines. I am trying it as an exercise. There are actually not 50 files, but I meant it could be more than 2. Here are actual files I created: first.txt
/vol/cat,feline /vol/dog,canine /vol/cat,feline /vol/cat,feline /vol/amphibian,FROG /vol/amphibian,FROG
second.txt
9,/vol/elephant,fourfeet 1999,/vol/dolphin,fish 10,/vol/cat,feline 1111,/vol/goldfish,fish 2222,/vol/spider,arachnid 5555,/vol/camel,dromedary 3333,/vol/wolf,canine
I am trying to do the following: 1. select the /vol/cat,feline as the element common in the array - this will require that the first column be excluded. 2. If the /vol/cat,feline is found (if an element is found in common to the array, print the ID # - for example #10. Here is what I did so far:
use strict; sub get_animal { open my $FILE, '<', shift or die $!; return map {chop; $_ => $_} <$FILE>; } my %a = get_animal '/tmp/first.txt'; my %b = get_animal '/tmp/second.txt'; { print "$_\n" for grep {$_} @a{keys %b}; }
It works if the column with the numbers in it is deleted from second.txt. I don't know how to make it compare the first and second columns from first file with the second and third columns from the second file. After that, it needs to return the ID # when it finds a match. Any ideas?

In reply to Re^2: comparing multiple files for patterns -- oneliner explained by 2015_newbie
in thread comparing multiple files for patterns by 2015_newbie

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.