#!/usr/bin/perl die "Usage: $0 -r\n" unless ( grep /^-r$/, @ARGV); my $testingfile = new_tmpfile_name(); print "Pretending to do something with $testingfile...\n"; exit 0; #-------------------------------------------------------------------- # Make up a temporary file name that is not already in use # elsewhere and arrange for it to be deleted automatically when # the program exits. # # This will get you in trouble if you ever use it with mod_perl. # BTW: 90% of this is stolen from the Ram recipe number 7.5 #-------------------------------------------------------------------- sub new_tmpfile_name { use IO::File; use POSIX qw(tmpnam); my ($name, $fh); # try new temp filenames 'til we get one that doesn't exist do { $name = tmpnam() } until $fh = IO::File->new($name, O_RDWR|O_CREAT|O_EXCL); # install atexit-style handler so that when we exit or die # we automatically delete this temporary file END { unlink($name) or die "Couldn't unlink $name : $!" } return $name; }