3
使用領帶::文件時,在試圖回答一個聰明的方法的old question,我要嘗試這個,不知道它是否會成功:意外行爲上__DATA__
#!/usr/bin/env perl
use strict;
use warnings;
use Tie::File;
tie(my @data, 'Tie::File', \*DATA) or die "Cannot tie DATA";
foreach (@data) {
print;
}
foreach (@data) {
print scalar reverse;
}
__DATA__
one
two
three
four
five
six
我預計它要麼工作,或死亡;我得到了什麼是意外:
#!/usr/bin/env perluse strict;use warnings;use Tie::File;tie(my @data, 'Tie::File', \*DATA) or die "Cannot tie DATA";foreach (@data) { print;}foreach (@data) { print scalar reverse;}__DATA__onetwothreefourfivesixlrep vne/nib/rsu/!#;tcirts esu;sgninraw esu;eliF::eiT esu;"ATAD eit tonnaC" eid ro) ATAD*\ ,'eliF::eiT' ,[email protected] ym (eit{) [email protected] (hcaerof;tnirp }{) [email protected] (hcaerof;esrever ralacs tnirp }__ATAD__enoowteerhtruofevifxis
如何在地球上沒有試圖扳平__DATA__
爲Tie::File
做到了扳平腳本,chomp
太?
現貨。除了'chomp','Tie :: File'也會自動chomping,除非你不告訴它。 –
無與倫比的標籤團隊迅速獲得。這是最好的一個好奇,最壞的是一個錯誤。謝謝。 –
DATA上的'tell'和'seek'不起作用,但我相信你有問題。我懷疑,如果你將一個打開的句柄綁定到某處,那麼'Tie :: File'首先會返回到開頭。 –