Use of uninitialized value $period的问题
时间:2010-10-04
来源:互联网
大家好,我是个Perl的初学者,在用Perl来写让电脑作图的程序时,遇到了一个问题无法解决。当我用Windows的Command line来运行时,提示的错误信息如下:
Use of uninitialized value $period in substitution <s///> at graph_gp_select.pl line 8, <TMP> line 1.
Use of uninitialized value $period in concatenation <.> or string at graph_gp_select.pl line 14.
程序的代码如下:
#!/usr/bin/perl -w
# Read in the data from files
#reads inn serial number from Fortran run from file "tmp"
open TMP, "tmp";
my $title_text = <TMP>;
my $period = <TMP>;
$title_text =~ s/\s//g;
$period =~ s/\s//g;
close TMP;
my $plotfile = $title_text.'.txt';
my $outputfile =$title_text.'_conc_select.png';
$title_text = $title_text.'; period = '.$period; (Line 14)
open (GNUPLOT, '|pgnuplot') or die "open: $!"; (pgnuplot是我用的作图软件)
print GNUPLOT <<EOF;
set terminal png
set title "$title_text"
set pointsize 2.0
set xtic
set mxtics 0.1
set ytics
set y2tics
set mytics 5
set xlabel "time, a.u."
set ylabel "nr, NR, NO3-, NMR, NO3_set (au)"
set y2label "NIT2:NIT4 (au), promoter saturation ratio (psr)"
set grid
set output 'graph_select.png'
plot "$plotfile" usi 1:2 title "nr" w lines, "$plotfile" usi 1:3 title "NR" w lines, "$plotfile" usi 1:4 title "NO3-" w lines, "$plotfile" usi 1:8 title "NMR" w lines, "$plotfile" usi 1:9 title "NIT2:NIT4" axes x1y2 w lines, "$plotfile" usi 1:10 title "psr" axes x1y2 w lines, "$plotfile" usi 1:11 title "NO3_set" w lines
set output "$outputfile"
plot "$plotfile" usi 1:2 title "nr" w lines, "$plotfile" usi 1:3 title "NR" w lines, "$plotfile" usi 1:4 title "NO3-" w lines, "$plotfile" usi 1:8 title "NMR" w lines, "$plotfile" usi 1:9 title "NIT2:NIT4" axes x1y2 w lines, "$plotfile" usi 1:10 title "psr" axes x1y2 w lines, "$plotfile" usi 1:11 title "NO3_set" w lines
EOF
#unlink ("tmp");
close (GNUPLOT) or die "close!";
请哪位朋友帮我查一下,谢谢了!
Use of uninitialized value $period in substitution <s///> at graph_gp_select.pl line 8, <TMP> line 1.
Use of uninitialized value $period in concatenation <.> or string at graph_gp_select.pl line 14.
程序的代码如下:
#!/usr/bin/perl -w
# Read in the data from files
#reads inn serial number from Fortran run from file "tmp"
open TMP, "tmp";
my $title_text = <TMP>;
my $period = <TMP>;
$title_text =~ s/\s//g;
$period =~ s/\s//g;
close TMP;
my $plotfile = $title_text.'.txt';
my $outputfile =$title_text.'_conc_select.png';
$title_text = $title_text.'; period = '.$period; (Line 14)
open (GNUPLOT, '|pgnuplot') or die "open: $!"; (pgnuplot是我用的作图软件)
print GNUPLOT <<EOF;
set terminal png
set title "$title_text"
set pointsize 2.0
set xtic
set mxtics 0.1
set ytics
set y2tics
set mytics 5
set xlabel "time, a.u."
set ylabel "nr, NR, NO3-, NMR, NO3_set (au)"
set y2label "NIT2:NIT4 (au), promoter saturation ratio (psr)"
set grid
set output 'graph_select.png'
plot "$plotfile" usi 1:2 title "nr" w lines, "$plotfile" usi 1:3 title "NR" w lines, "$plotfile" usi 1:4 title "NO3-" w lines, "$plotfile" usi 1:8 title "NMR" w lines, "$plotfile" usi 1:9 title "NIT2:NIT4" axes x1y2 w lines, "$plotfile" usi 1:10 title "psr" axes x1y2 w lines, "$plotfile" usi 1:11 title "NO3_set" w lines
set output "$outputfile"
plot "$plotfile" usi 1:2 title "nr" w lines, "$plotfile" usi 1:3 title "NR" w lines, "$plotfile" usi 1:4 title "NO3-" w lines, "$plotfile" usi 1:8 title "NMR" w lines, "$plotfile" usi 1:9 title "NIT2:NIT4" axes x1y2 w lines, "$plotfile" usi 1:10 title "psr" axes x1y2 w lines, "$plotfile" usi 1:11 title "NO3_set" w lines
EOF
#unlink ("tmp");
close (GNUPLOT) or die "close!";
请哪位朋友帮我查一下,谢谢了!
作者: hys850415 发布时间: 2010-10-04
本帖最后由 zhlong8 于 2010-10-04 21:57 编辑
open TMP, "tmp";
my $title_text = <TMP>;
my $period = <TMP>;
这里按你的第一个错误提示就是说执行到这里 $period 根本没有读取任何内容,因为 $title_text 没有报错,初步判定为你的文件只有一行,所以 $peroid 根本读不到任何内容。另外你 open 的时候没有检察系统错误,试下加上 open TMP, '<', 'tmp' or die $!;
暂时就想到这两个原因
open TMP, "tmp";
my $title_text = <TMP>;
my $period = <TMP>;
这里按你的第一个错误提示就是说执行到这里 $period 根本没有读取任何内容,因为 $title_text 没有报错,初步判定为你的文件只有一行,所以 $peroid 根本读不到任何内容。另外你 open 的时候没有检察系统错误,试下加上 open TMP, '<', 'tmp' or die $!;
暂时就想到这两个原因
作者: zhlong8 发布时间: 2010-10-04
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28