我在网上练习 perl 作业,并在 Sandbox 中找到了这个。
如何编写一个 perl 脚本,将 -> 添加到每行的前面,将 <- 添加到每一行的末尾。然后它会报告行数、最长行的长度以及原始输入中的总字节数。例如,输入文件
//Input File
Hi there.
This is Fred.
Who are you?
应该产生输出:
//Output File
->Hi there.<-
->This is Fred.<-
->Who are you?<-
3 lines, longest 13 characters, 37 bytes total.
我只能在此代码行的开头添加->:
#!/usr/bin/perl
use strict;
use warnings;
open(FH,"input.pl") or die "cannot open file: $!\n"; #Input File
open(NEWFH,"> output.pl") or die "cannot write\n"; #Output File
print "opened file\n";
while(<FH>){
print NEWFH "-> $_ ";
}
close FH;
close NEWFH;
你能帮我在行尾添加“->”吗