【发布时间】:2019-09-16 19:57:02
【问题描述】:
我制作了一个 Perl 脚本来列出指定文件的内容,但我还想查看文件内容的行号。 Perl 中的哪些函数可以实现这一点?
这是我的代码:
#!/usr/local/bin/perl
use warnings;
use strict;
print "Specify the file you want to look at:\n";
my $file_name = <STDIN>;
chomp $file_name;
open(FH, '<', $file_name) or die "Cannot open $file_name: $!";
print "This is the listed content of: $file_name\n";
while(<FH>){
print $_;
}
close(FH);
这就是我运行脚本时发生的事情,这也是我希望它做的事情。
Actual result Wished result
Hello 1. Hello
my 2. my
name 3. name
is 4. is
Janne 5. Janne
【问题讨论】: