0
#!/usr/bin/perl
use warnings;
use strict;
use feature qw{ say };
my $kw1 = 'Session Initiation Protocol (REGISTER)';
my $kw2 = 'CSeq: 3 REGISTER';
my $instance_counter;
my @first;
my @next;
my $myfile = "Input.txt";
open my $out_file1, '>', 'hello1.txt' or die "$!";
open my $out_file2, '>', 'hello2.txt' or die "$!";
open my $out_file3, '>', 'hello3.txt' or die "$!";
open DATA, $myfile or die "Can't open file: $!";
while (<DATA>) {
if (my $match = (/\Q$kw1/ .. /\Q$kw2/)) {
++$instance_counter if 1 == $match;
if (1 == $instance_counter) {
print $out_file1 $_;
}
elsif (2 == $instance_counter){
print $out_file2 $_;
}
else {
print $out_file3 $_;
}
}
}
我上面的程序將$ kw1和$ kw2之間的每個模式輸出到單獨的文本文件。是否有任何想法可以自動概括我對這些實例的搜索(即沒有匹配模式)並相應地生成輸出文本文件?如何在Perl中使用範圍運算符概括模式匹配搜索
是的..工作正常。謝謝 – rocky