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

微信扫码抢红包网站做做竞价网站要准备什么条件

微信扫码抢红包网站做,做竞价网站要准备什么条件,php网站建设培训,怎么在网站上做音乐引言 记录自己跳进的【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.yayakq.cn/news/639044/

相关文章:

  • 恩施州建设局网站自助建站的平台
  • 网站首眉怎么做wordpress 添加php
  • 上海企业网站域名备案的网站名称
  • 网站开发网站制作wordpress英文版教程
  • 网站策划师有前途吗在哪个网站上做外贸好
  • 网站标题第一个词天元建设集团有限公司 李增启
  • 菠菜网站的代理怎么做的建立网站的目录结构应注意哪些问题
  • 旅行社网站建设策划书技术支持 湘潭网站建设
  • 网站维护 网站建设属于什么wordpress设置密码链接
  • 设计良好的网站一般需要怎么做微网站是官网的手机站
  • 如何建立自己手机网站wordpress主机系统
  • 南京网站微信建设网页课程设计心得体会
  • 视频分享网站建设难吗摄影官网
  • 深圳如何建立公司自己网站岳阳网站建设哪里便宜
  • 如何做外围网站的代理百度站长号购买
  • 有声小说网站开发百度关键词规划师入口
  • 中国建设门户网站国外采购平台
  • 网站导航是做链接赚钱么手机免费在线搭建网站
  • 做电影网站投资多少网站流量来源
  • 正规做网站职业教育网站建设可行性报告
  • 做外贸家纺资料网站六安市建设网站市场信息价
  • 备案的时候需要网站吗哪些网站可以做百科来源
  • 网站开发素材大岭山镇仿做网站
  • 做安卓开发要去看哪些网站安徽省六安市城乡建设厅网站
  • 水陆运输类网站如何建设房产信息查询网
  • 网站建站大约多少钱网站后台管理系统很慢
  • 怎样登录柳州建设网站江苏网站建设培训
  • 手把手教你做网站 怎么注册域名怎么用域名进网站
  • 手机微网站第二年续费吗wordpress主题在哪
  • 哈尔滨优质官网建站企业windows 做网站服务器