List Info

Thread: Re: return file handger




Re: return file handger
country flaguser name
United States
2007-05-10 13:52:56

>>&gt;>> "jiqiang" == jiqiang yao < jiqiang123%40yahoo.com">jiqiang123yahoo.com> writes:

jiqiang&gt; I want to write a subroutine for openfile (see below).
jiqiang> However, the subroutine failed to be returned to
jiqiang> $fhandle. Can anybody tells me why?

Yes, stop using package-based filehandles. Use lexical filehandles.

sub openfile {
open my $handle, "<", shift or die "Cannot open: $!";
return $handle;
}

But if it's this short, I wouldn't even write a subroutine.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<; merlyn%40stonehenge.com">merlynstonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

__._,_.___
.

__,_._,___
[1]

about | contact  Other archives ( Real Estate discussion Medical topics )