【发布时间】:2009-06-24 22:47:08
【问题描述】:
我正在 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
以下是我的代码:
#!/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;
输出
reached here1
1
reached here 3
reached here1
1
reached here 3
【问题讨论】: