in reply to Re: scratching the surface of File::Temp
in thread (code) scratching the surface of File::Temp
I wouldn't be surprised if it's explained in the module's pod and I'm just not picking up on it.#!/usr/bin/perl -w use strict; use File::Temp qw(tempfile unlink0 ); use vars qw($fh $filename); my $template = 'fileXXXXXXXXXX'; my $dir = '/tmp/'; ($fh, $filename) = tempfile($template, DIR => $dir) or die "Error creating $filename: $!"; print $fh "\nS'working?\n" or die "Error writing to $filename: $!"; close $fh or die "Error closing $filename: $!"; print "\nUnlinking $filename\n<ENTER> to continue, CTRL+C to abort.\n" +; my $continue = (<STDIN>); unlink0 ($fh, $filename) or die "Error unlinking file $filename safely: $!"
Update: Good monk a says below "not supposed to close $fh... unlink0 will handle..."
A-ha! that seems to do the trick. 8^)
Update #2: But if I don't "close $fh" then "print $fh "\nS'working?\n" or die;" doesn't really happen. So I'm still doing something wrong 8^(
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: (2) scratching the surface of File::Temp (unlink w/o $filehandle ?)
by a (Friar) on Feb 10, 2001 at 09:55 UTC | |
by tilly (Archbishop) on Feb 10, 2001 at 22:47 UTC |