简体   繁体   English

Perl循环不打印字符

[英]Perl loop not printing out character

This one has got me. 这个人有我。

This works: 这有效:

print "Processing Feed\n";
while ( my @p = $mainex->fetchrow_array ) {
    my $iis = "$pcount";
    print "$iis\n";
    # ... Do Other Stuff Here
    $pcount++;
}

Which gives: 这使:

Processing Feed
1
2
3
4
5
6
7
8
9
10
...

This does not work (removed the \\n from line 4): 这不起作用(从第4行中删除\\ n):

print "Processing Feed\n";
while ( my @p = $mainex->fetchrow_array ) {
    my $iis = "$pcount";
    print "$iis";
    # ... Do Other Stuff Here
    $pcount++;
}

Which simply gives: 这只是给出了:

 Processing Feed

I was trying to build a counter that would output the count of the record it was up to using something like: 我正在尝试构建一个计数器,它将使用以下内容输出记录的计数:

while( Something ){
    print "\b\b\b\b\b\b\b\b\b\b\b";
    print "$count";
    $count++;
    # Do stuff here
}

Any ideas why when there is no \\n in the second example nothing is printing to screen? 任何想法,为什么当第二个例子中没有\\ n时,没有什么是打印到屏幕? I have done it many times before and cannot figure out why it is not working. 我以前做了很多次,无法弄清楚它为什么不起作用。

The newline at the end of the print triggers a flush of stdout, which prints to the screen. 打印结束时的换行触发stdout的刷新,打印到屏幕上。 If you add $|++ to the top of your perl script, it will turn on autoflushing for stdout and you will see your numbers. 如果你在perl脚本的顶部添加$|++ ,它将打开stdout的autoflushing,你会看到你的数字。

Buffered I/O. 缓冲I / O.

The data is flushed to the screen when there's a newline, or when the buffer is full (which may be 512 bytes or 4096 bytes or some other fairly substantial number). 当有换行符或缓冲区已满时(可能是512字节或4096字节或其他相当大的数字),数据会刷新到屏幕。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM