2009-07-04 42 views

回答

4

這段代碼似乎認爲它只適用於open ::的IO :: Scalar版本。這可能是因爲沒有與文件句柄關聯的基礎操作系統級文件沒有關聯。

#!/usr/bin/perl 

use 5.010; 
use strict; 
use warnings; 

my $fakefile = "foo\nbar\nbaz\n"; 
open my $fake, "<", \$fakefile 
    or die "could not open fakefile [$fakefile]: $!"; 

open my $script, "<", $0 
    or die "could not open self for reading: $!"; 

print "fake: ", my_fileno($fakefile), "\nreal: ", my_fileno($script), "\n"; 

sub my_fileno { 
    my $fileno = fileno shift; 
    $fileno //= "undef"; 
    return $fileno; 
} 
+0

我想它只適用於IO :: Scalar,如你所說。 – 2009-07-04 13:46:00