Ris*_*iss -2 string perl compare
以下是代码示例:
while (@filelines){
#splice the line to a array
print "the string to be compared is $filelines[$i] with $FN_Accessories_Header\n";
if (chomp($filelines[$i]) eq $FN_Accessories_Header){
print "The file name is FN_Accessories.csv and first line is header\n";
}
else {
print "The scanning process will be terminated as the first line is not header\n";
exit;
}
}
Run Code Online (Sandbox Code Playgroud)
两个变量的内容相同,但if语句中的print不会执行.
asd_bsd;asdf_asdf;weroi_asdf;asdf_asdf;asdf_wer;rty_tyu;sdf_erty;qwe_123;asdffff_asdfrs;
chomp不返回缩短的字符串,它返回删除的字符数.
chomp @filelines;
for my $line (@filelines) {
if ($line eq $FN_Accessories_Header) {
...
Run Code Online (Sandbox Code Playgroud)