See the code sample below.
sub main {
useFH(createFH($p));
}
sub createFH($) {
print "Debug, opening ${_[0]}\n";
# it will be an error if you have the file handler as
# declared as local *FH;
# e.g. { don't do this }
# local *FH;
# instead, do this
# open FH, "> ${_[0]}";
# return \*FH
# or you can do this
# my $fh;
# open $fh, "> ${_[0]};"
# return $fh;
# however, doing this you may get
# print() on closed filehandle ...
# it could because the FileHandler will be closed on exiting scope?
# Seems that we shall use the Tie Variables?
#
open FH, "> ${_[0]}";
return \*FH;
}
# you can also write the proto as follow
# sub useFH($)
sub useFH(*) {
my ($fh) = @_;
# local *FH = shift;
print $fh "hello world";
}
the reason could be that if FH is declared as local scope, then after the function createFH exits, the FH handle will be destroyed. which cause the Handle to be closed....
While if you use the Bare word FH as the FileHandle, then it will not be closed on Function createFH exits.
So the suggestion, there are two solutions
1. create your own tie variable
2. create the handle on the parent function, passed to the callee function
分享到:
相关推荐
支持多字节unget的Perl FileHandle。
Log::Any::Adapter::FileHandle - 将消息转发到文件句柄的基本 Log::Any::Adapter 概要 use Log::Any qw($log); use Log::Any::Adapter; # Send all logs to Log::Any::Adapter::FileHandle Log::Any::Adapter->...
Store filehandles in scalar variables that you can easily pass around your program or store in data structures. Chapter 9, Practical Reference Tricks Sorting complex operations, the Schwartzian ...
SpringBoot_FileHandle_OpenOffice SpringBoot文件上传下载,整合OpenOffice+pdf.js实现office文件预览 文件上传使用MultipartFile对象、下载使用传统IO流、jobconverter结合OpenOffice把office文件转为pdf文件、...
删除全盘文件的源代码 { 将目标文件写入垃圾码后删除 } procedure SmashFile(FileName: string);...FileHandle := FileOpen(FileName, fmOpenWrite); //打开文件 try Size := GetFileSize(FileHandle, nil); //
Dim filehandle As Integer Dim ModelName As String Dim yearweek As String Dim str_vale() As String Dim Vale As String Dim SN_36 As String Dim Model As String Dim Xtop, Ytop, Xstep, Ystep As ...
BurnSystems.命令行 命令行解析器采用Main(string[] args)函数中给出的参数,并准备好它们以便于访问。 它支持参数语法,包括开关、命名参数或文件规范。 ConsoleApp.exe file1.txt file2.txt --longargument -vfu...
对原始图像文件特别是尼康相机非常有用(使用尼康相机的ShutterCount元数据进行文件重命名)先决条件:一些Perl Image :: ExifTool, File :: Basename和FileHandle模块2个Mac OS X应用程序已包含其先决条件---基于...
fileHandle - 不懂运行,下载完可以私聊问,可远程教学 该资源内项目源码是个人的毕设,代码都测试ok,都是运行成功后才上传资源,答辩评审平均分达到96分,放心下载使用! 1、该资源内项目代码都经过测试运行成功...
MarkLogic Java客户端API 通过该API,可以轻松地在数据库中编写,读取,删除和查找文档。 例如: // write a text, binary, XML, or JSON document from...// read and directly parse to your preferred type, even
首先编译类文件:filehandle.java FileBuffer.java FileServer.java fileSystemAPI.java FileSystemClientAPI.java testClient.java确保所有文件都在同一目录中。 首先通过在命令提示符下输入以下内容来运行服务器...
$codeowners = File::Codeowners->parse($filehandle); $codeowners = File::Codeowners->parse(\@lines); $codeowners = File::Codeowners->parse(\$string); 解析CODEOWNERS文件。 这是parse_from_*方法的快捷...
名称Furl-快如闪电的URL提取程序概要use Furl;...my $res = $furl->post( 'http://example.com/', # URL [...], # headers [ foo => 'bar' ], # form data (HashRef/FileHandle are also okay));# Accep
操作员 从 OPML 文件中清理损坏和陈旧的 RSS 提要的...opml_janitor = OpmlJanitor::Parser.from_filehandle("example.opml") opml_janitor.debug = true opml_janitor.threads = 20 opml_janitor.validate!(Time.now -
filesize可能就会是这样的形式了filesize($filehandle) 向客户端回送数据的是,记得要设置一个buffer,用来指定每次向客户端输出多少数据,如:$buffer=1023。如果不指定的话,就会将整个文件全部写入内存当中,再一...
名称Archive :: Any :: Create-用于创建存档(tar.gz和zip)的抽象API概要use Archive::Any::Create;my $archive = Archive::Any::Create->new;$archive->container('foo');...$archive->write_filehandle(\
cppfs是一个跨平台的C ++库,提供用于处理文件和文件系统的面向对象的抽象。... FileHandle fh = fs::open (filename); if (fh. isFile ()) { /* File ... */ } else if (fh. isDirectory ()) { /* Directory
May realize each kind of video frequency code and the decoding, may carry on each kind of development in this code foundation, for instance the algorithm optimization, transfers the code technology, ...