in reply to Re: Comparing two files one with numebers and the other one with ranges range and printing matches
in thread Comparing two files one with numebers and the other one with ranges range and printing matches
I have change the code to loop throw my output looks like this folded IMB Count: 15 No Matched IMB Count: 1 selfmail IMB Count: 14 I now need to be able to create files for each instance: first file will be folded.txt with 15 of the original number seconde file will be nomatch.txt with the original as well and same for the third. any advice??#!/usr/bin/perl use warnings; use strict; use feature qw{ say }; unlink $outputfile; unlink $outputfile2; unlink $outputfile3; sub trimspaces { my @argsarray = @_; $argsarray[0] =~ s/^\s+//; $argsarray[0] =~ s/\s+$//; return $argsarray[0]; } open(INPUT , "< D:\\Home\\test\\imbfilelist.txt") or die $!; open(INPUT2 , "< D:\\Home\\test\\imbrange.txt") or die $!; my $n; my $value; my @ranges; my $isMatch; my $printed; my $fVersion; my %versionHash=(); while (<INPUT2>) { chomp; my ($version, $from, $to) = (split /,/)[ 1, 2, 3 ]; push @ranges, [ $from, $to, trimspaces($version)]; if (!exists $versionHash{trimspaces($version)}) { $versionHash{trimspaces($version)}=0; } } $versionHash{"No Matched"}=0; # foreach my $key (keys %fileHandleHash) # { # close $fileHandleHash{$fVersion}; # } close INPUT2; while (<INPUT>) { $isMatch=0; $n = substr($_,12-1,9); for my $r (@ranges) { if ( $n >= $r->[0] && $n <= $r->[1]) { $fVersion=$r->[2]; if (exists $versionHash{$fVersion}) { $versionHash{$fVersion}++; } $isMatch=1; last; } } if (!$isMatch) { $versionHash{"No Matched"}++; } } foreach my $key (keys %versionHash) { print STDOUT "$key IMB Count: " . $versionHash{$key} . "\n"; } close INPUT;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Comparing two files one with numebers and the other one with ranges range and printing matches
by CountZero (Bishop) on Jun 16, 2015 at 06:31 UTC | |
by emadmahou (Acolyte) on Jun 16, 2015 at 13:50 UTC | |
by CountZero (Bishop) on Jun 20, 2015 at 11:18 UTC |