当前位置: 首页 > news >正文

做网站最快的编程语言搜索引擎优化的步骤

做网站最快的编程语言,搜索引擎优化的步骤,建设部国家标准网站,wordpress汉化新闻主题引言 记录自己跳进的【perl】编程小坑,以己为鉴。 1、eq $str1 "12345\n"; $str2 "12345"; if ($str1 eq $str2) { print "OK" } 上述代码不会打印 OK。特别在读文件 ,匹配字符串时容易出BUG。 案例说明: 有…



引言

记录自己跳进的【perl】编程小坑,以己为鉴。


1、eq

$str1 = "12345\n"; $str2 = "12345";

if ($str1 eq $str2)

{

        print "OK"

}

上述代码不会打印 OK。特别在读文件 ,匹配字符串时容易出BUG。

案例说明:

有一个需求,对于test_A.txt文件的每一行,找出test_B.txt文件中与之相同的内容,打印该行内容,并显示行号。

test_A.txt 以及 test_B.txt 文件中内容:

如果你的代码是这么写的:

open test_A_handle , "<D:\\Perl_WorkSpace\\test_A.txt\n" or die "can't open the file test_A.txt\n";
open test_B_handle , "<D:\\Perl_WorkSpace\\test_B.txt\n" or die "can't open the file test_B.txt\n";$pos = tell(test_B_handle);#获取文件指针位置,因为刚打开文件,所以 $pos为0while (my $str1 = <test_A_handle>)
{seek(test_B_handle,$pos,0);#使文件指针回到文件头my $cnt = 0;while(my $str2 = <test_B_handle>){   $cnt++;if ($str1 eq $str2){print "match string :" . $str1 . " ";print "line num : " . $cnt . "\n";}}
}
close test_A_handle;
close test_B_handle;

那么你得到的结果是:

match string :1111111line num : 5
match string :1111111line num : 9
match string :2222222line num : 6
match string :3333333line num : 7
match string :4444444line num : 8
match string :1234567line num : 1
match string :0000000line num : 2
match string :0978157line num : 3

乍一看没啥毛病,但是细看发现test_A.txt文件中第一行,在test_B.txt文件的第12行也出现了,但是没有匹配到。原因在哪里呢?因为test_B.txt文件的第12行是最后一行,行末没有换行符\n,因为perl认为 "1111111" 不等于 "1111111\n"。那么我们在比较之前用chomp函数将换行符去掉即可解决这个小BUG。代码:

open test_A_handle , "<D:\\Perl_WorkSpace\\test_A.txt\n" or die "can't open the file test_A.txt\n";
open test_B_handle , "<D:\\Perl_WorkSpace\\test_B.txt\n" or die "can't open the file test_B.txt\n";$pos = tell(test_B_handle);#获取文件指针位置,因为刚打开文件,所以 $pos为0while (my $str1 = <test_A_handle>)
{   chomp $str1;seek(test_B_handle,$pos,0);#使文件指针回到文件头my $cnt = 0;while(my $str2 = <test_B_handle>){   chomp $str2;$cnt++;if ($str1 eq $str2){print "match string :" . $str1 . " ";print "line num : " . $cnt . "\n";}}
}
close test_A_handle;
close test_B_handle;

输出:

2、split 

my $str_1 = "ab cd ef gh 12 34 56\n";
my @array_1 = split(' ',$str_1);
print @array_1;
print "1234567890";

上述代码片段输出结果是什么?

abcdefgh1234561234567890

还是

abcdefgh123456

1234567890

split拆分之后,将\n去除了。也即是说$array_1[6] = "56" 而非 “56\n”

http://www.yidumall.com/news/1560.html

相关文章:

  • 聊城做网站建设建立一个国外的网站
  • 小米路由做网站服务器网络销售新手入门
  • 佛山外包网站建设seo网页优化公司
  • 哪里做网站比较好客户管理系统
  • 慈城旅游网站建设策划书青岛设计优化公司
  • 网络营销推广方法餐饮优化手机流畅度的软件
  • 惠济免费网站建设谷歌平台推广外贸
  • 做货代用什么网站找客户如何创建自己的网址
  • 卖汽车配件怎么做网站外贸营销推广
  • 如何做代购网站获客
  • 企业国家信用信息公示整站优化排名
  • 拼多多网站分析网络营销专员的就业前景
  • 有了代刷网的源码怎么做网站宜兴百度推广
  • 武汉网站设计公司管司最近时政热点新闻
  • 为什么百度搜出来的网站只有网址没有网站名和网页摘要.亚马逊seo推广
  • wordpress语言系统免费的seo网站
  • 做网站销售好累seo入门基础教程
  • 有哪些做笔译的网站什么是seo搜索优化
  • c2c电子商务网站定制开发关键词查找网站
  • 海南网站建设哪家好北京seo设计公司
  • 电子商务网站建设需求说明书上海网站快速排名提升
  • 佛山哪里有网站开发如何网站优化排名
  • 长沙网络工程学院天津seo管理平台
  • 网站估值怎么做aso优化是什么
  • 官方网站下载万能钥匙百度视频推广怎么收费
  • 微信网站开发多少钱站长之家 站长工具
  • 腾讯云怎么备案网站如何让百度搜索到自己的网站
  • 艾睿网站建设第三方网站流量统计
  • pc网站和手机网站营销推广是什么意思
  • 黑五手表网站百度排行