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

前端 未结 7 1988
南旧
南旧 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:14

    Better result with split can be done by:

    my $result="LINE1
    line2
    linE3
    ";
    #attention, /^/m allows properly operate on multiline string using regex
    #and ^ is character empty begin all lines
    foreach my $resultLine (split /^/m, $result) {
        print $resultline;  #withount '\n' because it have got
        #some checks & operations
    }
    

提交回复
热议问题