How can I process a multi line string one line at a time in perl with use strict in place?

前端 未结 7 1952
南旧
南旧 2021-02-15 13:32

I\'m trying to figure out the proper PBP approved way to process a multi line string one line at a time. Many Perl coders suggest treating the multi line string as a filehandle

相关标签:
7条回答
  • 2021-02-15 14:16

    Convert the multi-line string into a list of single line strings with split:

    my @resultLines = split /\n/, $result;     #   or  /\r\n/ for Windows?
    foreach my $resultLine (@resultLines) {
        if ($resultLine =~ m/joe/) {
            $matchLines
                = $matchLines . "\t" 
                     . $resultLine . "\n";  # put \n or \r\n back on the end
        }
    }
    
    0 讨论(0)
提交回复
热议问题