Skip to content

Instantly share code, notes, and snippets.

@hongz1
Forked from odyniec/tempdir.pl
Created August 18, 2018 20:06
Show Gist options
  • Save hongz1/35cd9014b3bdad5f235dbb3e1d0a6f2f to your computer and use it in GitHub Desktop.
Save hongz1/35cd9014b3bdad5f235dbb3e1d0a6f2f to your computer and use it in GitHub Desktop.
An example Perl program that uses File::Temp to create a temporary directory for the time of program execution.
#!/usr/bin/env perl
use Cwd;
use File::Temp;
# Remember the current directory
my $oldcwd = getcwd;
# Create a temporary directory
my $dir = File::Temp->newdir;
# Go to the temporary directory
chdir $dir;
# ... do your stuff, create files in the temporary directory ...
# Go back to the previous directory
chdir $oldcwd;
# The temporary directory will be deleted when the program exits
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment