I am writing a Perl script that performs various filesystem operations and I am interested in adding a "preview" mode to it. A rough outline of the script would look like:
use Filesystem::Preview; if ($ARGV[0] eq "--preview") { shift; enable_filesystem_preview(); } ... rename $file_from, $file_to or die "Could not move file: $!\n"; chmod 0777, $file_to or die "Could not chmod file: $!\n"; unlink $temp_file or die "Could not delete file: $!\n";
Now if you invoke script.pl, it performs the file operations; but if you invoke script.pl --preview its output is
rename file1.txt -> file2.txt chmod 0777 file2.txt unlink /tmp/tempfile.dat
...but no actual changes are made to the filesystem.
I looked on CPAN and did not see such a module. Does anyone know of such a module?
Ideally, it might also cache actions so your script could include code like:
use Filesystem::Preview; enable_filesystem_preview(CACHE => 1); ... print_cached_filesystem_actions(); if (user_confirmation("Perform operations?")) { execute_cached_filesystem_actions(); } else { die "User confirmation required\n"; }
In reply to File operations "preview" mode? by jh
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |