WC -Sx- Jones wrote:
Christian Stalp wrote:
Hello together,
I want to create a tempfile via the function tempfile.
But I want a certain path and name for the file.
The option DIR and SUFFIX and s.o. is clear to me but how can I
set the name of the file? For Exam: temp_file.lock or somethink
like that!?
CPAN is your friend:
http://search.cpan.org/~tjenness/File-Temp-0.14/Temp.pm
I searched on tempfile
Did you find a way to set the filename to "temp_file.lock"? The OP has obviously RTFM.
Not sure about that RTFM as OP stated:
>>>set the name of the file? For Exam: temp_file.lock or somethink >>>like that!?
So to be safe - here, a code fragment:
# Variables to set - my $path = '/tmp/'; my $ext = '_temp_file.lock'; # WARNING: Do Not Use HTML! # End of user configurable items...
my ( $sec, $min, $hour, $mday, $mon, $year, $wday) = localtime;
my $lt = sprintf("%02d%02d%02d%02d%02d%4d%d", $sec, $min, $hour, $mday, ++$mon, ($year + 1900), $wday);
$lt .= $ext; $path .= $lt; my $slt = scalar localtime;
# print "Using $path as temp file..."; exit;
use 5.004; use Fcntl qw(:DEFAULT :flock); sysopen(BLACKHOLE, "$path", O_WRONLY | O_CREAT) or die "can't create $path: $!"; flock(BLACKHOLE, LOCK_EX) or die "can't lock $path: $!"; truncate(BLACKHOLE, 0) or die "can't truncate $path: $!";
__END__
Cheers; -Sx-
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>