Skip to content

Instantly share code, notes, and snippets.

@odyniec
Last active February 11, 2022 13:36
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save odyniec/731082c77b501c536ff1 to your computer and use it in GitHub Desktop.
Save odyniec/731082c77b501c536ff1 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