Perl match only returning “1”. Booleans? Why?

后端 未结 6 885
星月不相逢
星月不相逢 2021-01-18 13:18

This has got to be obvious but I\'m just not seeing it.

I have a documents containing thousands of records just like below:

Row:1 DATA:
[0]37755442
[         


        
6条回答
  •  囚心锁ツ
    2021-01-18 13:33

    my($foo) = $record=~ /Defect/;
    print STDOUT $foo;
    

    Rather than this you should do

    $record =~ /Defect/;
    my $foo = $&; # Matched portion of the $record.
    

    As your goal seems to be to get the matched portion. The return value is true/false indicating if match was successful or not.

    You may find http://perldoc.perl.org/perlreref.html handy.

提交回复
热议问题