Use of uninitialized value?

Use of uninitialized value?



写了一段代码,如下:
#!/usr/bin/perl -w

open (NEWTXT, "C:/Documents and Settings/Administrator/My Documents/新建文本文档.ascii"||die "Cannot open this file!";
open (OUTPUT, ">C:/Documents and Settings/Administrator/My Documents/输出.ascii"||die "Cannot open the file match_Yeast_A1!";
@array=<NEWTXT>;
foreach $array (@array)
{if ($array=~/(\d+), (\d+)/)
{$RT=$1; $intensity=$2;}
print OUTPUT $RT, "\t", $intensity, "\n";
}
close (NEWTXT);
close (OUTPUT);

运行是提示未初始化值(红色标识),本人刚用perl不久,不知道问题到底出在哪儿?不是先产生了个数组了么?怎么会说没有初始化?还请各位大侠不吝赐教,谢谢!!!
在前面加上:
my $RT="";
my $intensity="";
if ($array=~/(\d+), (\d+)/)
{$RT=$1; $intensity=$2;}
print OUTPUT $RT, "\t", $intensity, "\n";

如果if不成立的话, $RT, $intensity就不存在了


另外,
请使用use strict;
$arrya和@array不要同名
请关闭代码中的表情
图片完全没必要, 贴上output就行了
... ...
#!/usr/bin/perl -w


use strict;
use warnings;

open (NEWTXT, "C:/Documents and Settings/Administrator/My Documents/新建文本文档.ascii")||die "Cannot open this file!";
open (OUTPUT, ">C:/Documents and Settings/Administrator/My Documents/输出.ascii")||die "Cannot open the file match_Yeast_A1!";
my @array=<NEWTXT>;
my $RT="";
my $intensity="";
foreach my $array (@array)
{if ($array=~/(\d+), (\d+)/)
{$RT=$1; $intensity=$2;}
print OUTPUT $RT, "\t", $intensity, "\n";
}
close (NEWTXT);
close (OUTPUT);
开头加上
1 use strict; use warnings;
2 将$RT,$intensity申明为全局变量
3 检查正则表达式是否匹配
可以这么写

[Copy to clipboard] [ - ]
CODE:
if(...){
   ...
}else{ print"No match\n";$RT=$intensity="NoMatch";