I have the following short perl script rename.pl. How can I translate this script to one liner perl syntax? And how to combine the perl one liner in find command?
rename.pl
#!/usr/bin/perl
$op = shift;
for (@ARGV) {
$was = $_;
eval $op;
die $@ if $@;
rename($was,$_) unless $was eq $_;
}
My current find syntax:
find /tmp -name "*$NAME*" -exec \
./rename.pl \
's/\Q$ENV{NAME_THAT_WE_WANT_TO_CHANGE}\E/$1$ENV{NEW_NAME}$2/' {} +
The find syntax that I want to build:
find /tmp -name "*$NAME*" -exec \
< perl one liner line ....... > \
's/\Q$ENV{NAME_THAT_WE_WANT_TO_CHANGE}\E/$1$ENV{NEW_NAME}$2/' {} +
File::Findin the script turning the whole thing into a simple command. I know that seems crazy as you will not get to spend as much time typing and making mistakes, but... $0.02perl(he copy-pasted that perl code), then he's more likely to make mistakes with that, and it's probably going to be less efficient. He could usemmvorzmvthat are designed for that kind of task (or evenrename, an off the shelfperlscript for that).