这个答案有两个独立的概念:
注意quotemeta的使用.当用户输入包含RE特定字符时,这很重要(如果您不处理它,甚至可能会创建一个illigel RE).
这是代码:
print "Looking for: ";
my $input = <>;
chomp $input;
my $re = quotemeta $input;
open my $fh, "<", "myfile.txt" or die $!;
while( <$fh> ) {
print if /$re/;
}
close $fh;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1552 次 |
| 最近记录: |