我有两个文件。我试图从两个文件中找出所有常见数字而不重复。以下是两个文件的详细信息
myresult
0..351
12..363
24..375
36..387
48..399
注释
272..1042
代码:
#!/usr/bin/perl
open( $inp0, "<myresult" ) or die "not found";
open( $inp2, "<annotation" ) or die "not found";
open( $out, ">output" );
my @arr2 = <$inp0>;
my @arr4 = <$inp2>;
my $from = ( split /\.\./, $arr2[0] )[0];
my $to = ( split /\.\./, $arr2[-1] )[1];
for my $i ( $from .. $to ) {
print $out "$i\n" if grep inside( $i, $_ ), @arr2 and grep inside( $i, $_ ), @arr4;
}
sub inside {
my ( $i, $range ) = @_;
my ( $from, $to ) = split /\.\./, $range;
return ( $from <= $i and $i <= $to );
}
输出应该是:从272到399的数字。但是这段代码只给出了0。