in reply to Comparing two files one with numebers and the other one with ranges range and printing matches
#!/usr/bin/perl use warnings; use strict; use feature qw{ say }; open my $F2, '<', 'file2' or die $!; my @ranges; while (<$F2>) { chomp; my ($version, $from, $to) = (split /,/)[ 1, 2, 3 ]; push @ranges, [ $from, $to, $version ]; } open my $F1, '<', 'file1' or die $!; while (<$F1>) { chomp; my $n = substr $_, 11, 9; my $printed; for my $r (@ranges) { if ($r->[0] <= $n && $n <= $r->[1]) { say "$_,$r->[2]"; $printed = 1; } } say "$_, no match" unless $printed; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Comparing two files one with numebers and the other one with ranges range and printing matches
by emadmahou (Acolyte) on Jun 13, 2015 at 02:48 UTC | |
by choroba (Cardinal) on Jun 13, 2015 at 19:24 UTC | |
by emadmahou (Acolyte) on Jun 16, 2015 at 13:43 UTC |