jh has asked for the wisdom of the Perl Monks concerning the following question:
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"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: File operations "preview" mode?
by jethro (Monsignor) on Aug 26, 2010 at 19:44 UTC | |
by jh (Beadle) on Aug 26, 2010 at 20:06 UTC | |
by graff (Chancellor) on Aug 27, 2010 at 05:03 UTC | |
|
Re: File operations "preview" mode?
by ikegami (Patriarch) on Aug 27, 2010 at 03:14 UTC | |
|
Re: File operations "preview" mode?
by Marshall (Canon) on Aug 27, 2010 at 01:08 UTC | |
|
Re: File operations "preview" mode?
by JavaFan (Canon) on Aug 26, 2010 at 21:28 UTC |