in reply to Re^3: Filtering Output from two files
in thread Filtering Output from two files
use strict; <br> use warnings; <br> use Data::Dumper; <br> my $file1 = 'file1';<br> my $file2 = 'file2'; <br> #reading file1 into a hash<br> my %hash;<br> open (my $fh,'<',$file2) or die $!;<br> while(my $line=<$fh>)<br> {<br> chomp $line;<br> $hash{$line}=1;<br> print Dumper %hash;<br> }<br> close $fh;<br> #reading file2 line by line <br> open (my ($fh2),'<',$file1) or die $!; <br> while (my ($row) = <$fh2>) {<br> chomp $row;<br> # next if $row =~ /^\s*$/;<br> my (@fields) = split(/\|/, $row);<br> print $row if exists $hash{$fields[0]};<br> }<br> close $fh2;<br>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Filtering Output from two files
by roboticus (Chancellor) on Feb 06, 2018 at 05:09 UTC | |
by Anonymous Monk on Feb 06, 2018 at 06:04 UTC | |
by Anonymous Monk on Feb 06, 2018 at 06:19 UTC | |
by roboticus (Chancellor) on Feb 06, 2018 at 08:47 UTC | |
by Anonymous Monk on Feb 06, 2018 at 09:12 UTC | |
| |
by Anonymous Monk on Feb 06, 2018 at 06:22 UTC | |
by Anonymous Monk on Feb 06, 2018 at 06:30 UTC |