2015_newbie has asked for the wisdom of the Perl Monks concerning the following question:
use strict; use strict; use warnings; my %file2; open my $file2, '<', '/tmp/dog.txt' or die "Couldn't open file2: $!"; while ( my $line = <$file2> ) { ++$file2{$line}; } open my $file1, '<', '/tmp/cat.txt' or die "Couldn't open file1: $!"; while ( my $line = <$file1> ) { print $line if $file2{$line}; }
The script correctly returns "police." But the problem is that I have 50 files like this & I need to assign files to a variable so that it can compare one file to another. Does anyone know how to get multiple files in a script like this? so there may be horse.txt and lama.txt and camel.txt and tiger.txt and I want to check each file against dog.txt and cat.txt. Is this possible? I would also like to know if part of a pattern can be compared -such as grep /poli/ - I have only been able to do it by line.dog.txt ARF police set cat.txt meow arf police
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: comparing multiple files for patterns
by kennethk (Abbot) on Dec 31, 2015 at 01:29 UTC | |
|
Re: comparing multiple files for patterns
by GrandFather (Saint) on Dec 31, 2015 at 03:19 UTC | |
|
Re: comparing multiple files for patterns -- oneliner explained
by Discipulus (Canon) on Dec 31, 2015 at 09:45 UTC | |
by 2015_newbie (Novice) on Jan 04, 2016 at 03:21 UTC | |
by Discipulus (Canon) on Jan 04, 2016 at 09:03 UTC | |
|
Re: comparing multiple files for patterns
by Laurent_R (Canon) on Dec 31, 2015 at 18:46 UTC |