| Server IP : 217.160.0.212 / Your IP : 216.73.216.6 Web Server : Apache System : Linux info 3.0 #1337 SMP Tue Jan 01 00:00:00 CEST 2000 all GNU/Linux User : u119869361 ( 9600978) PHP Version : 8.4.28 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /kunden/proc/self/root/proc/thread-self/root/usr/share/doc/rename/examples/ |
Upload File : |
# examples of using the options HASH from C<File::Rename::Options::GetOptions>
# based on code from "Craig Sanders" <cas@taz.net.au>
# Bug #146138 for File-Rename: how to access options hash in rename script?
# [rt.cpan.org #146138]
#
# with user code from command line
#
use strict;
use warnings;
use File::Rename qw(rename);
use File::Basename qw(dirname);
use File::Path qw(make_path);
my $options = File::Rename::Options::GetOptions() or
die "Bad options\n";
@ARGV = map {glob} @ARGV if $^O =~ m{Win}msx;
my $expr = delete $options->{_code} or die "No code\n";
my $eval = eval qq( sub { $expr } ) or die $@;
my %seen;
my $code = sub {
&$eval;
my $dir = dirname($_);
if (! -e $dir) {
if ($options->{no_action}) {
print "#mkdir($dir)\n" unless $seen{"$dir"}++;
} else {
make_path("$dir", { verbose => 1 });
};
} elsif (! -d "$dir") {
print STDERR "$_: $dir exists but is not a directory!\n";
return
}
};
rename(\@ARGV, $code, $options);