Why aren't newlines being printed in this Perl code?

前端 未结 3 1155
清歌不尽
清歌不尽 2020-12-12 04:17

I have some simple Perl code:

#!/usr/bin/perl

use strict;   # not in the OP, recommended
use warnings; # not in the OP, recommended

my $val = 1;
for ( 1 ..         


        
3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-12 05:03

    This is more of a comment than an answer, but I don't know how else to make it and the question is already answered anyway.

    Note that using say instead of print neatly sidesteps the whole issue. That is,

    #!/usr/bin/perl
    
    use 5.010;
    use strict;
    use warnings;
    
    my $val = 1;
    for ( 1 .. 100 ) {
        $val = ($val * $val + 1) % 8051;
        say ($val / 8050);
    }
    

    works as intended without the issue even coming up. I'm still amazed at how useful say is, given it's such a tiny difference.

提交回复
热议问题