Hi,
I need to create a bunch of temporary files to store information. Best solution seems to be File::Temp, as the files will automatically be removed when script ends/dies.
The thing is, I would like to store the filehandle references in a hash, this would make it easy to maintain, loop, ...
I have to admit, I'm not well versed in FileHandles and/or references to FileHandles. This is what I would like to do:
But I get the following error:
String found where operator expected at test.pl line 23, near "} "Hello World!\n
""
(Missing operator before "Hello World!\n"?)
syntax error at test.pl line 23, near "} "Hello World!\n""
Execution of test.pl aborted due to compilation errors.
I must have forgotten a \,$ or * somewhere.
Can anybody help?
AD AUGUSTA PER ANGUSTA
Thierry
I need to create a bunch of temporary files to store information. Best solution seems to be File::Temp, as the files will automatically be removed when script ends/dies.
The thing is, I would like to store the filehandle references in a hash, this would make it easy to maintain, loop, ...
I have to admit, I'm not well versed in FileHandles and/or references to FileHandles. This is what I would like to do:
Code:
#!/usr/bin/perl -w
# Modules
use strict;
use File::Temp qw/tempfile/;
# Declare variables
my (%tempfiles);
# Loop and create handles
foreach ('host','user','feature') {
# Make a temporary file
my ($fh, $filename) = tempfile( DIR => $ENV{TEMP} );
# Store in global variable
$tempfiles{$_}{'handle'} = $fh;
$tempfiles{$_}{'filename'} = $filename;
}
# Printout to file
print $tempfiles{host}{handle} "Hello World!\n";
But I get the following error:
String found where operator expected at test.pl line 23, near "} "Hello World!\n
""
(Missing operator before "Hello World!\n"?)
syntax error at test.pl line 23, near "} "Hello World!\n""
Execution of test.pl aborted due to compilation errors.
I must have forgotten a \,$ or * somewhere.
Can anybody help?
AD AUGUSTA PER ANGUSTA
Thierry