Last active
February 11, 2022 13:36
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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