Good monk ChOas showed me that I needed to import "unlink0".
And I replaced $path in DUNWERK2 with $filehandle and renamed function to NOWITWERX.
Also fixed typo by replacing my$filename with my $filename in 2 places.
That seems to fix everything, except DUNWERK still doesn't appear to create tempfile.
Since I can now create and unlink with NOWITWORKS syntax, this is good enough for now.
Thanks and ++ to ChOas. 8^)
Updated codelet below.
#!/usr/bin/perl -w
# filetemptest.pl
# 2001-01-19
# 2001-01-18
# File::Temp 0.11 Perl 5.00503
# File::Spec 0.82 Debian 2.2 "Espy"
use strict;
use File::Temp qw(tempfile unlink0);
&WERX();
&WERX2();
&DUNWERK();
&NOWITWERX();
##################################################################
sub NOWITWERX {
my $template = 'nowitwerxXXXXXXXXXX';
my $dir = '/tmp/';
(my $fh, my $filename) = tempfile($template, DIR => $dir);
print "\nCreated filehandle $fh with filename $filename.\n\n";
print "Press (almost) any key to unlink.\n";
my $continue = (<STDIN>);
unlink0 ($fh, $filename) or die " NOWITWERX: Error unlinking file
+ $filename safely.\n";
}
##################################################################
sub DUNWERK {
my $template = 'dunwerkXXXXXXXXXX';
my $dir = '/tmp/';
my $fh = tempfile($template, DIR => $dir);
print "\nCreated filehandle $fh.\n";
print "Press (almost) any key to continue\n";
my $continue = (<STDIN>);
}
##################################################################
sub WERX2 {
my $template = 'werx2XXXXXXXXXX';
my $dir = '/tmp/';
(my $fh, my $filename) = tempfile($template, DIR => $dir);
print "\nCreated filehandle $fh with filename $filename.\n\n";
print "Press (almost) any key to continue\n";
my $continue = (<STDIN>);
}
##################################################################
sub WERX {
(my $fh, my $filename) = tempfile();
print "\nCreated filehandle $fh with filename $filename.\n";
print "Press (almost) any key to continue\n";
my $continue = (<STDIN>);
}
##################################################################
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|