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

前端 未结 7 1998
南旧
南旧 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

    You can also use a regexp as an iterator:

    my $data = q{Hello
    This
    Is
    A
    Test};
    
    while( $data =~ /(.+)$/mg) {
        print "line is '$1'\n";
    }
    

    This is slightly less convoluted compared to using a filehandle that represents a string.

提交回复
热议问题