in reply to return file descriptor from function
Use a lexical filehandle and pass it back, it behaves just as a scalar.
$ cat > rubbish sdfhi rtrthr dgdf $ perl -Mstrict -Mwarnings -e ' > my $file = q{rubbish}; > my $fh = openFunc( $file ); > print while <$fh>; > > sub openFunc > { > my $fileToOpen = shift; > open my $fileHandle, q{<}, $fileToOpen > or die qq{open: $fileToOpen: $!\n}; > return $fileHandle; > }' sdfhi rtrthr dgdf $
I hope this was what you meant from your rather terse question and that I have answered your question.
Cheers,
JohnGG
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: return file descriptor from function
by Laurent_R (Canon) on Aug 10, 2013 at 22:48 UTC | |
Re^2: return file descriptor from function
by solomon243 (Novice) on Aug 12, 2013 at 08:34 UTC |
In Section
Seekers of Perl Wisdom