Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

(code) Re: can create with File::Temp but not unlink (close enough 8^)

by ybiC (Prior)
on Jan 19, 2001 at 18:56 UTC ( #52994=note: print w/replies, xml ) Need Help??


in reply to can create with File::Temp but not unlink

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>); } ##################################################################
  • Comment on (code) Re: can create with File::Temp but not unlink (close enough 8^)
  • Download Code

Replies are listed 'Best First'.
Re: Re: can create with File::Temp but not unlink (close enough 8^)
by a (Friar) on Jan 20, 2001 at 11:35 UTC
    I can't get File-Temp to install via PPM (its there but ...) but the readme cautions about permissions on the dir. However, DUNWERK uses:
    my $fh = tempfile($template, DIR => $dir);
    and the rest use:
    (my $fh, my $filename) = tempfile($template, DIR => $dir);
    so ... array returns in scalar context or something?

    a

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://52994]
help
Chatterbox?
erix considers showing this to choroba , thinks better of it
[choroba]: LanX we used to mock Hare Krishna processions signing "Hare Rama" carrying the margarine conatiners
[choroba]: :-D
[LanX]: What about Czech an Chechen ambessy?
[AnomalousMonk]: LanX: Rama had (has?) a high (much higher than typical asteroid) rate of axial (again, unusual, I think) spin for its artificial gravity.
LanX pity there is no Germs embassy ...
[choroba]: LanX We merged them to save money.

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (14)
As of 2017-11-22 17:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (327 votes). Check out past polls.

    Notices?