5
A
回答
10
匹配操作符默認使用$_
但除非它是在一個while循環使用,因此沒有被存儲在$_
的<>
操作者不按默認保存到$_
。
從perldoc perlop
:
I/O Operators ... Ordinarily you must assign the returned value to a variable, but there is one situation where an automatic assignment happens. If and only if the input symbol is the only thing inside the conditional of a "while" statement (even if disguised as a "for(;;)" loop), the value is auto‐ matically assigned to the global variable $_, destroying whatever was there previously. (This may seem like an odd thing to you, but you’ll use the construct in almost every Perl script you write.) The $_ vari‐ able is not implicitly localized. You’ll have to put a "local $_;" before the loop if you want that to happen. The following lines are equivalent: while (defined($_ =)) { print; } while ($_ =) { print; } while() { print; } for (;;) { print; } print while defined($_ =); print while ($_ =); print while ; This also behaves similarly, but avoids $_ : while (my $line =) { print $line }
4
<>
僅在while(<>)
構造神奇。否則,它不會分配給$_
,所以/include/
正則表達式沒有任何可匹配的內容。如果你跑這跟-w
的Perl會告訴你:
Use of uninitialized value in pattern match (m//) at ....
你可以解決這個問題:
$_ = <> until /include/;
爲了避免警告:
while(<>)
{
last if /include/;
}
相關問題
- 1. Perl MySQL - 如果特定字段匹配,如何跳過更新或插入行?
- 2. 如何刪除perl中的特定行?
- 3. 如何解析perl中的特定行?
- 4. 跳轉到jsgrid中的特定行
- 5. 如何跳到一個指定的行,然後解析 - perl
- 6. 如何跳轉到XCode 4中特定的代碼行?
- 7. 如何跳轉到RichTextBox中的特定行?
- 8. 的Perl:特定行
- 9. 如何將輸入從Perl中輸入到Java命令中?
- 10. 跳轉到特定行的末尾
- 11. 如何跳轉到特定視圖?
- 12. 如何「跳轉」到特定元素?
- 13. 選擇特定的行特定的列和特定的輸入
- 14. 如何跳轉到特定的代碼行
- 15. Java - 如何使程序運行直到輸入特定值
- 16. 如何從特定行讀取到另一行 - Perl
- 17. 如何使用用戶輸入刪除ArrayList中的特定行
- 18. 如何選擇從輸入文件Python中的特定行
- 19. 在Python中,如何跳至腳本中的特定行?
- 20. 如何提取perl中的特定列?
- 21. 在匹配一個單詞後跳過特定行數PERL
- 22. 如何跳過awk中的特定行並打印剩餘的
- 23. 如何將特定輸入元素集中到Ember 2中
- 24. 在Perl中,我如何加入前兩行輸入?
- 25. Postgresql csv輸入,跳過行
- 26. Serial.read()跳過串行輸入
- 27. 如何使用Perl將輸入輸入到Java應用程序?
- 28. Python:如何跳過輸入文件中的重複行?
- 29. 跳轉到UINavigationController中的特定點
- 30. 如何跳過文件中的特定行?
真的嗎?我不知道。謝謝 – user44511 2008-12-11 17:47:15