Like you point out,
a, if
$fh is used instead of
TMP, I lose
$filehandle as soon as
$fh is closed. So how can I
unlink0 with no
$filehandle without generating "Use of uninitialized value @ /usr/local/lib/site_perl/File?Temp.pm line (1525|1584), <STDIN> chunk 1" ?
#!/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: $!"
I wouldn't be surprised if it's explained in the module's pod and I'm just not picking up on it.
cheers,
Don
striving for Perl Adept
(it's pronounced "why-bick")
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^(
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.