perl – 从文件中的行引用双引号内的字符串

perl – 从文件中的行引用双引号内的字符串,第1张

概述我的文件内容如下: 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_comptest_comp3
解决方法
my $compname = $_ = ~ m/"(.*?)"/;

=〜与=〜不同,但是赋值和bitwise negation

而你想要的是,

my ($compname) = $_ =~ m/"(.*?)"/;

要不就,

my ($compname) = /"(.*?)"/;
总结

以上是内存溢出为你收集整理的perl – 从文件中的行引用双引号内的字符串全部内容,希望文章能够帮你解决perl – 从文件中的行引用双引号内的字符串所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/1245081.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-07
下一篇2022-06-07

发表评论

登录后才能评论

评论列表(0条)

    保存