second.txt/vol/cat,feline /vol/dog,canine /vol/cat,feline /vol/cat,feline /vol/amphibian,FROG /vol/amphibian,FROG
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: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
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?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}; }
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |