暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

perl-第二弹 出现!第一个报错

流浪骆驼 2020-12-03
1937
记得点击蓝字关注我们哦!


01

上期回顾

perl 特点:

  •     perl没有严谨的缩进规则

  •     perl注释是使用#

  •     perl语句以;结束

  •     print、chomp内建函数


02

执行perl脚本


以下为Error.pl 脚本内容:

# 输出到屏幕 Hello, world
print "Hello, world\n";
# 输出到屏幕 How are you doing?
print "How are you doing?\n
# 输出到屏幕 Have you found any problems in this script?
print "Have you found any problems in this script?\n";

   

(1)首先检查是否已经安装perl软件,检查方法:perl -v

          如果输出类似以下内容表示已正确安装

C:\Users\DELL>perl -v


This is perl 5, version 30, subversion 1 (v5.30.1) built for MSWin32-x64-multi-thread


Copyright 1987-2019, Larry Wall


Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.


Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl". If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.

上面显示我的电脑安装的perl版本为v5.30.1,Larry Wall 大佬,感兴趣可以了解一下~


(2)切换到脚本路径下,执行:perl Error.pl

C:\Users\DELL>cd Desktop


C:\Users\DELL\Desktop>perl Error.pl
Bareword found where operator expected at Error.pl line 3, near "print "Have"
(Might be a runaway multi-line "" string starting on line 2)
(Do you need to predeclare print?)
String found where operator expected at Error.pl line 3, at end of line
(Missing semicolon on previous line?)
syntax error at Error.pl line 3, near "print "Have you "
Can't find string terminator '"' anywhere before EOF at Error.pl line 3.


 (3)上面显示没有正常输出结果,   

程序问我们 (Missing semicolon on previous line?),上一行是否遗漏了一个引号呢?上一行是line 2,所以原因就是第二行遗漏了“(记得结尾加;)。修改后重新执行即可~


本报错是由于perl程序中字符串是一对“ ”引起了的,但是程序进行语法检查,发现第二行只有一个引号。所以就报错Bareword。


03

总结

(1)倘若看到"Bareword"一词,则意味着某个词语两边缺少引号。

(2)perl中字符串一般是由引号引来的(类似 “aaaa”)。

(3)遇到问题莫慌,首先要确定什么问题,哪里出现了问题,然后就是找出解决办法即可。

        就像本次,我们首先知道遗漏引号了,然后知道在第二行,然后确定问题是第二行结尾少”,添加上就问题解决~




文尾福利:

参数
含义
-v
输出perl版本信息
-c
检查perl语法
-e
单行脚本
-n

打印指定行内容,类似awk


好看请点这里~
文章转载自流浪骆驼,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论