[EMAIL PROTECTED] wrote:
I am attempting to use the File::Temp libraries to read and write to
auto generated files but I am having trouble reading from the file
after the data has been written.
That is because the file pointer is at the end of the file.
I believe this to be something
specific to how tempfile() works because I have been able to
successfully read from a scalar handle the old fashioned way.
No, it is the way all filehandles work.
open $filHandle, "file.txt";
however,
#==========Hello World
use strict;
use File::Temp ('tempfile');
my $tempFile;
my $fileName;
($tempFile, $fileName) = tempfile();
if (defined $tempFile){ print $fileName . "\n"; }
print $tempFile "Hello World!\n";
if (defined $tempFile){ print "debug\n"; }
print $tempFile->getline; #line 15
#below code results in the same error
#my $rd = <$tempFile>;
#print $rd;
If you now want to read from the same filehandle you have to reset the
filehandle back to the beginning of the file:
use Fcntl ':seek';
seek $tempFile, 0, SEEK_SET or die "Cannot seek '$fileName' $!";
my $rd = <$tempFile>;
print $rd;
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/