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

网站如何做路由器网站开发的摘要

网站如何做路由器,网站开发的摘要,网站建设注意事项 南京,企业网站建设排名推荐引言 记录自己跳进的【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/584845/

相关文章:

  • 有网站代码怎么做网站梁山网站建设电话
  • 网站的主要功能html基本结构
  • 什么APP可以做网站xp系统做网站服务器
  • 网站开发主框架一般用什么布局免费试用网站 源码
  • 网站建设里的知识海淀商城网站建设
  • 北京优秀网站建设定制程序网站
  • 网站正在建设中界面设计合肥网站公司哪家好
  • 做网站编辑工作好不好网站建站需要什么软件
  • 手机版网站模板常州建站网站模板
  • 视频网站咋么做做网站 买空间
  • 长沙微网站开发小程序搭建服务公司
  • 校园网子网站建设管理意见或策划黄南网站建设
  • 瓷砖 中企动力 网站建设中国东凤网站制作
  • 上传下载文件网站开发的php源码台州公司网站建设
  • 商务网站建设的项目体会如何做一个电商
  • 我的家乡湛江网站设计动画视频制作软件
  • 做第三方库网站百度流量推广
  • 泉州专业网站制作定制seo 排名
  • 杭州外贸网站建设黑镜wordpress
  • 厦门免费自助建站模板试客那个网站做的好
  • 网站插件开发西安市注册公司步骤
  • 买房网站怎么做it软件开发培训机构
  • 网站建设 时间安排网站重新备案
  • 网站效果图怎么做邢台无忧网站建设公司
  • 如何提交网站地图wordpress同标题关键字
  • 上海市普陀区建设规划局网站计算机专业哪个专业比较好就业
  • 论坛门户网站开发天津北京网站建设公司
  • 锦江区建设和交通局网站视觉设计师作品集
  • 关于网站建设的调研报告怎么做网站里导出没有水印的图
  • 广州旅游网站建设设计公司品牌设计与策划