我的代码如下所示:
#!/usr/bin/perl -w
use strict;
use warnings;
my $i = 1;
my @old_names = glob "/root/pics/*.jpg";
my $new_name = "picture$i";
foreach my $old_name (@old_names) {
rename($old_name, $new_name) or
die "Couldn't rename $old_name to $new_name: $!\n";
} continue { $i++ }
当我执行脚本时它会删除图片,我做错了什么?
编辑:
这对我有用。
#!/usr/bin/perl -w
use strict;
use warnings;
my $i = 1;
my @old_names = glob "/root/pics/*.jpg";
foreach my $old_name (@old_names) {
my $new_name = "picture$i" . ".jpg";
rename($old_name, "/root/pics/$new_name") or die "Couldn't rename $old_name to $new_name: $!\n";
} continue { $i++ }
感谢大家的帮助。