我正在嘗試使用沒有裸詞 glob 的Device::SerialPort,請參閱底部的問題。
這是他們的例子:
$PortObj = tie (*FH, 'Device::SerialPort', $Configuration_File_Name)
print FH "text";
...但是用 *FH 污染命名空間感覺很臟...
tie(my $fh, ...)我像你一樣嘗試過,open (my $fh, ...)但Device::SerialPort沒有實作TIESCALAR,所以它給出了一個錯誤。
這是我的骯臟技巧,但它仍然使用裸詞,我什至無法將其限定為裸詞 glob:
# This does _not_ scope *FH, but shouldn't it?
{
$port = tie(*FH, 'Device::SerialPort', $ARGV[0]) or die "$ARGV[0]: $!";
$fh = \*FH; # as a GLOB
$fh = bless(\*FH, 'IO::Handle'); # or as an IO::Handle
}
print $fh "text"; # this works
print FH "text"; # so does this, but shouldn't *FH be scoped?
問題:
- 是否有可能以一種不會創建裸詞 glob 的方式進行系結?
- 為什么大括號不作用于 *fh?
uj5u.com熱心網友回復:
您可以使用local.
我希望這也能奏效:
use Symbol qw( gensym );
my $fh = gensym;
tie *$fh, ...
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/488112.html
下一篇:PerlDBI和臨時表
