[kw-pm] how to tell a perl script not to use /tmp?
Richard Dice
rdice at pobox.com
Tue Nov 11 07:07:44 PST 2008
>
> and, sadly, it appears to insist on using /tmp for its
> temporary work, but on the system i am forced to use, /tmp
> is 99% full. can someone show me how to modify that script
> to use, say, ~/tmp instead? thanks.
>
I suppose cleaning the garbage out of /tmp isn't an option? It really
should be, either by you or someone else. Being able to delete garbage out
of /tmp is why it's *called* /tmp
Given that you're specifying /tmp rather than C:/temp I'm assuming you're on
a Un*x system. This is good information to know.
This isn't really an issue of Perl so much as it is a matter of just reading
through the code and trying to find where it is that the constant string
/tmp would be introduced, and intercepting or recoding that one particular
line. Although, knowing something about Perl is going to help in that it
will give you a good place to start with reading documentation.
At the top of the program, notice:
#
# Include files
#
use Cwd;
use File::Temp 0.12 qw(tempdir tempfile);
use Getopt::Long 2.25;
use Pod::Usage;
use URI 1.17;
That File::Temp reference looks juicy. Read its docs online at
http://search.cpan.org/~tjenness/File-Temp-0.20/Temp.pm
I got this URL from http://search.cpan.org/ which is Teh R0xor!
In this documentation, I notice it says:
*tempfile*
This is the basic function to generate temporary files. The behaviour of the
file can be changed using various options:
$fh = tempfile();
($fh, $filename) = tempfile();
Create a temporary file in the directory specified for temporary files, as
specified by the tmpdir() function in
File::Spec<http://search.cpan.org/perldoc?File%3A%3ASpec>
.
There is at least one line in the program that uses this function,
my ($handle, $tmpfile) = tempfile( DIR => $temp_dir );
so this could be relevant info. Frankly, looking at this one line makes me
want to try just removing the '$temp_dir' variable and throwing '~/tmp' in
there, just to see how it works. (Or you could figure out where $temp_dir
is set and just set it to "~/tmp" instead.)
So anyhow, over to the docs for File::Spec,
http://search.cpan.org/~smueller/PathTools-3.29/lib/File/Spec.pm where
you'll see:
tmpdir
Returns a string representation of the first writable directory from a list
of possible temporary directories. Returns the current directory if no
writable temporary directories are found. The list of directories checked
depends on the platform; e.g. File::Spec::Unix checks $ENV{TMPDIR} (unless
taint is on) and */tmp*.
$tmpdir = File::Spec->tmpdir();
This might be your most elegant fix: just set the TMPDIR environment
variable to what you need it to be.
Cheers,
- Richard
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/kw-pm/attachments/20081111/a7222793/attachment.html>
More information about the kw-pm
mailing list