perl – 从文件中的行引用双引号内的字符串
发布时间:2020-12-16 06:19:15 所属栏目:大数据 来源:网络整理
导读:我的文件内容如下: Component (0463) "commonfiles"Component (0464) "demo_new_comp"Component (0467) "test_comp" (removed)Component (0469) "test_comp3" (removed)Component (0465) "textfiles1 需要从具有(已删除)并放置在数组中的每一行的双引号内提
我的文件内容如下:
Component (0463) "commonfiles" Component (0464) "demo_new_comp" Component (0467) "test_comp" (removed) Component (0469) "test_comp3" (removed) Component (0465) "textfiles1 需要从具有(已删除)并放置在数组中的每一行的双引号内提取字符串. my $fh = new IO::File; $fh->open("<comp.log") or die "Cannot open comp.log"; my @comp_items; while (<$fh>) { if ( $_ =~ /removed/ ) {; my $compName = $_ = ~ m/"(.*?)"/; print " Componnet Name : "$compName"n"; } } 我没有得到正确的输出给出一些数字: "18446744073709551614" "18446744073709551614" 输出应该是: test_comp test_comp3 解决方法my $compName = $_ = ~ m/"(.*?)"/; =?与=?不同,但是赋值和bitwise negation 而你想要的是, my ($compName) = $_ =~ m/"(.*?)"/; 要不就, my ($compName) = /"(.*?)"/; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |