Perl's rename - how to append a counter?

别说谁变了你拦得住时间么 提交于 2019-12-06 15:50:31

The line of code in question is:

$c = sprintf(eval("%" . "$form", $cNumber));

You don't want the eval there; you can simply create the format as a string:

$c = sprintf("%$form", $cNumber));

The string (first argument) ends up containing the format requested, and sprintf() formats $cNumber using that.

The basic rename utility can handle that situation just fine:

$ rename '$_ = sprintf "%d - %s", ++$count, $_' files...
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!