perl文件句柄的傳遞


perl 返回文件句柄的2種方式

1.使用 \*

#!/usr/bin/perl
use strict;
sub openfile()
{
        
    my $path=shift;
    open(FILE,"$path") or die "Can't open $path $!\n ";
    
  return \*FILE;
    
}
my $temp=&openfile("config");
my @file=<$temp>;
print @file;

 

2.使用變量

#!/usr/bin/perl
use strict;
sub openfile()
{
    my $file;
    my $path=shift;
    open($file,"$path") or die "Can't open $path $!\n ";
    
    #close($file);
    return $file;
    
}
my $temp=&openfile("config");
my @file=<$temp>;
print @file;

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM