我在Perl中搜索一个字符串并将其存储在另一个标量变量中.我想打印这个标量变量.下面的代码似乎不起作用.我不确定出了什么问题,以及正确的方法是什么.为什么在程序中不存在时打印"1"?
正在运行的数据
数据
13 E 0.496 -> Q 0.724
18 S 0.507 -> R 0.513
19 N 0.485 -> S 0.681
21 N 0.557 -> K 0.482
Run Code Online (Sandbox Code Playgroud)
以下是我的代码:
#!/usr/bin/perl
use strict;
use warnings;
my $find = '\s{10}[0-9]{2}\s[A-Z]'; #regex. it can also be '\s{10}[0-9]{2}\s[A-Z]'
#both dont seem to work
my @element;
open (FILE, "/user/run/test") || die "can't open file \n";
while (my $line = <FILE>) {
chomp ($line);
print "reached here1 \n"; # to test whether it reading the program properly
my $value = $line=~ /$find/ ;
print "reached here 3 \n"; # to test whether it reading the program properly
print "$value \n";
}
exit;
Run Code Online (Sandbox Code Playgroud)
OUTPUT
reached here1
1
reached here 3
reached here1
1
reached here 3
Run Code Online (Sandbox Code Playgroud)