【发布时间】:2012-01-28 16:28:52
【问题描述】:
我正在尝试使用 ren-regexp 替换文件名中的字符,如下所示:
./ren-regexp.pl "s/_/-/g" *.jpg
我认为应该将 _ 替换为 - 在 jpgs 文件名中,但我得到的是:
./ren-regexp.pl: line 4: syntax error near unexpected token `newline'
./ren-regexp.pl: line 4: `<!DOCTYPE html>'
我也试过
perl ren-regexp.pl "s/_/-/g" *.jpg
这导致了很多错误,例如:
Bareword found where operator expected at ren-regexp.pl line 252, near "time class"
(Do you need to predeclare time?)
Bareword found where operator expected at ren-regexp.pl line 252, near ""js-relative-date" datetime"
(Missing operator before datetime?)
Bareword found where operator expected at ren-regexp.pl line 252, near ""2011-04-13T16:40:41-07:00" title"
(Missing operator before title?)
Number found where operator expected at ren-regexp.pl line 252, near "April 13"
(Do you need to predeclare April?)
Bareword found where operator expected at ren-regexp.pl line 262, near ""/msabramo/ren-regexp/tree/17026c762c41e2b88ed91bf78b63e54859b706e5" class"
(Missing operator before class?)
我尝试使用 GitHub 页面和此处显示的示例:
Mass replace characters in filenames from terminal?
我哪里错了?单独运行“perl ren-regexp.pl”也会导致上述错误。
【问题讨论】:
-
你确定你有一个好的下载吗?听起来你的程序很糟糕。 “ren-regexp.pl”在 250-260 行附近是什么样子的?
-
那个脚本,从它的外观上看,相当……写得不好。甚至不使用 strict 和 warnings,而且看起来已经很老了。
-
数百行糟糕的代码要做
perl -MFile::Copy=move -Mautodie -we 'for (@ARGV { my $new = $_; $new =~ s/_/-/g; move $_, $new; }' *.jpg? -
这是几年前的事,但在寻找答案时唯一不断弹出的内容。
-
好像是12年前写的,2005年最后更新了。