我在perl中运行一个简单的文件测试,代码如下:
my $f1 = "$pre_file";
unless (-e $1) {
print "\n Pre_check file does not exists! \n";
die;
}
Run Code Online (Sandbox Code Playgroud)
它打印以下输出:
Pre_check文件不存在!
死于./huawei-postcheck第81行.
但是我不希望最后一行"死于./huawei-postcheck第81行".
我想"死",没有错误信息.
可能吗?
我试图以表格格式打印输出.
我的剧本:
use strict;
my @heading=("FN","SN","BP","SUBBN","LgcBT");
my @values=("1","0","Front","Mother Board","MIU");
print "\n\n";
&HEADING;
print "\n";
&VALUES;
print "\n\n";
sub HEADING {
foreach (@heading) {
my $lgth1=length($_);
printf "%3s","| ";
printf "%${lgth1}s",$_;
}
}
sub VALUES {
foreach (@values) {
my $lgth2=length($_);
printf "%3s","| ";
printf "%${lgth2}s",$_;
}
}
Run Code Online (Sandbox Code Playgroud)
输出:
| FN | SN | BP | **SUBBN** | LgcBT
| 1 | 0 | Front | **Mother Board** | MIU
Run Code Online (Sandbox Code Playgroud)
我需要以一种方式打印输出,如果值比标题长,那么它会自动将标题长度调整为值.
以下是我的代码:
foreach my $node (@switch_list) {
chomp $node;
print "$node \n";
my $f3 = ">$node.txt";
chmod 0755, $f3;
open FILE3, "$f3" or die "Could not open file:$! \n";
}
Run Code Online (Sandbox Code Playgroud)
在这里,我想创建许多具有完全权限的文件,但似乎是使用权限创建的文件:0640而不是0755.
我有两个文件
file1的内容如下
================================================== =
OUTPUT1:---------
orange
india
US
xx
OUTPUT2:---------
orange-1
india-1
US-1
xx
Run Code Online (Sandbox Code Playgroud)
================================================== =
file2内容如下
OUTPUT1:---------
orange
india
US
xx
OUTPUT2:---------
orange-1
india-1
US-2
xx
Run Code Online (Sandbox Code Playgroud)
================================================== =
我想要两个不同的如下
-----------------------
OUTPUT1: No evolution
----------------------
OUTPUT2: Evolution found
Before:US-1
After:US-2
----------------------
Run Code Online (Sandbox Code Playgroud)
是否可以在perl中编写具有上述要求的脚本
任何帮助都感激不尽
我是perl的新手.
我有两个文本文件:
file1包含两行:
mahesh
bharti
Run Code Online (Sandbox Code Playgroud)
file2包含两行:
mahesh
orange
Run Code Online (Sandbox Code Playgroud)
你可以看到两个文件之间的区别是bharti和orange.不知怎的,我能够打印出差异.但我的要求是它应该打印如下.
Difference of file as below:
File1 contain: bharti
FIle2 contain: orange
Run Code Online (Sandbox Code Playgroud)
我目前使用perl编写的代码如下