免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2995 | 回复: 4
打印 上一主题 下一主题

Use of uninitialized value? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-10-23 19:35 |只看该作者 |倒序浏览


写了一段代码,如下:
#!/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不久,不知道问题到底出在哪儿?不是先产生了个数组了么?怎么会说没有初始化?还请各位大侠不吝赐教,谢谢!!!

论坛徽章:
0
2 [报告]
发表于 2007-10-23 21:12 |只看该作者
在前面加上:
my $RT="";
my $intensity="";

论坛徽章:
0
3 [报告]
发表于 2007-10-23 21:20 |只看该作者
if ($array=~/(\d+), (\d+)/)
{$RT=$1; $intensity=$2;}
print OUTPUT $RT, "\t", $intensity, "\n";

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


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

论坛徽章:
0
4 [报告]
发表于 2007-10-23 21:35 |只看该作者
#!/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);

论坛徽章:
0
5 [报告]
发表于 2007-10-24 09:46 |只看该作者
开头加上
1 use strict; use warnings;
2 将$RT,$intensity申明为全局变量
3 检查正则表达式是否匹配
可以这么写
  1. if(...){
  2.    ...
  3. }else{ print"No match\n";$RT=$intensity="NoMatch";
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP