KW.pm Only the Lonely #11

File::Temp

  • uses File::Spec

          use File::Temp;
          my $fh = tempfile;  # temporary file is opened, in suitable directory
          print $fh $big_data;
          exit;               # temporary file is automatically deleted.
  • or, you can get a filename and a filehandle

          ($fh, $filename) = tempfile;
  • By default, the second case does not delete temp file automatically because it was named.

  • However these defaults can be changed with various options:

          ($fh, $filename) = tempfile($template);
          ($fh, $filename) = tempfile($template, SUFFIX => $suffix)
          ($fh, $filename) = tempfile($template, UNLINK => 1);
  • template is of format: 'tempXXXXX' and Xs are replaced with random characters.

<< Previous | Index | Next >> Copyright © 2005 Daniel Allen