读取文件的简单程序报错了求指点
时间:2010-10-06
来源:互联网
- use strict;
- use warnings;
-
- main(@ARGV);
-
- sub main
- {
- my $line;
- open FH,"short.txt";
- while ($line=<FH>){
- print if($line =~ m|/|);
- }
- close FH;
- }
- sub message
- {
- my $m=shift or return;
- print "$m\n";
- }
- This page describes the syntax of regular expressions in Perl.
-
- If you haven't used regular expressions before, a quick-start
- introduction is available in perlrequick, and a longer tutorial
- introduction is available in perlretut.
-
- For reference on how regular expressions are used in matching
- operations, plus various examples of the same, see discussions of "m//",
- "s///", "qr//" and "??" in "Regexp Quote-Like Operators" in perlop.
-
- Matching operations can have various modifiers. Modifiers that relate to
- the interpretation of the regular expression inside are listed below.
- Modifiers that alter the way a regular expression is used by Perl are
- detailed in "Regexp Quote-Like Operators" in perlop and "Gory details of
- parsing quoted constructs" in perlop.
Use of uninitialized value in print at readshort.pl line 31, <FH> line 8.
Use of uninitialized value in print at readshort.pl line 31, <FH> line 9.
如果用$_就没事
- use strict;
- use warnings;
-
- main(@ARGV);
-
- sub main
- {
- my $line;
- open FH,"short.txt";
- while ($_=<FH>){
- print if($_ =~ m|/|);
- }
- close FH;
- }
- sub message
- {
- my $m=shift or return;
- print "$m\n";
- }
- #END
operations, plus various examples of the same, see discussions of "m//",
"s///", "qr//" and "??" in "Regexp Quote-Like Operators" in perlop.
作者: laohuanggua 发布时间: 2010-10-06
因为 while(<FH>) {} 等于 while (my $_ = <FH>) {}
要问为什么我估计是搞 Perl 那帮家伙太懒了,想少打几个字符,对于默认 $_ 为参数的函数也会很方便。而且以前 $_ 是不能 my 的
要问为什么我估计是搞 Perl 那帮家伙太懒了,想少打几个字符,对于默认 $_ 为参数的函数也会很方便。而且以前 $_ 是不能 my 的
作者: zhlong8 发布时间: 2010-10-06
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28