English 中文(简体)
更名为Perls——如何对反响?
原标题:Perl s rename - how to append a counter?

http://www.evolt.org/renaming_files_with_perl” rel=“nofollow”>renamingutil,这些装置与Perl的安装有关。 如何在Perl regexp中附上反响? 这是一个相关的问题,例如,目前名录中档案的编号问题:

rename  s/^/<here I d like 纽约总部 have a number of a file being processed>/g  * 

例如,如何改名:

fileA
fileB
fileC

纽约总部

1 - fileA
2 - fileB
3 - fileC

http://www.ohchr.org。

I ve added the counter feature ($c variable) - see here. It works fine - but when I try 纽约总部 specify the counter format:

rename_c.pl -c 5.2f  s/^/$c - /  * 

它说:

 Useless use of concatenation (.) or string in void context at line 120. 

and it doesn t really use the format I 纽约总部ld it 纽约总部 use. This must be some simple syntax mistake in a line number 120. Can You please take a look?

最佳回答

The line of code in question is:

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

页: 1 在这里,你可以简单地确定形式,以示:

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

插图(第一论点)最终含有所要求的格式和<编码>印本(>格式$cNumber

问题回答

更名为“基本用途”可处理这种情况:

$ rename  $_ = sprintf "%d - %s", ++$count, $_  files...

如果你在macOS,并且使用通过<代码>brew 更名为<>/代码>的安装工具,那么应当采取以下措施:

rename -N ...01 -X -e  $_ = "${_}-counter-$N"  your_files

例:

> rename -n -N ...01 -X -e  $_ = "${_}-counter-$N"  *.png
 iPad-Pro12.9-4g at 11.24.52.png  would be renamed to  iPad-Pro12.9-4g at 11.24.52-counter-01.png 
 iPad-Pro12.9-4g at 11.25.09.png  would be renamed to  iPad-Pro12.9-4g at 11.25.09-counter-02.png 
 iPad-Pro12.9-4g at 11.25.17.png  would be renamed to  iPad-Pro12.9-4g at 11.25.17-counter-03.png 

http://www.strong.html。 本身

<<>txtfile>

perl -le  ($old=$_) && s/^/++$n."-$`"/eg && print for <*.txt> 

<><>>>

perl -le  ($old=$_) && s/^/++$n."-$`"/eg && rename($old,$_) for <*.txt> 

  • perl -le run a one-liner
  • ($old=$_) save the old name
  • s/^/++$n."-$`"/eg do the substitution | note that it has a back-tick
    • /^/ match the begging
    • ++$n start a counter from 1
    • ."-$`" append counter to this
    • /eg run globally and e is for evaluation
  • rename($old,$_) rename the $old => $_
  • for <*.txt> loop over list of txt file

www.un.org/Depts/DGACM/index_spanish.htm 您可以重新命名一切照样,并提前重新命名您可能希望使用的

screenshot

“enter像





相关问题
Why does my chdir to a filehandle not work in Perl?

When I try a "chdir" with a filehandle as argument, "chdir" returns 0 and a pwd returns still the same directory. Should that be so? I tried this, because in the documentation to chdir I found: "...

How do I use GetOptions to get the default argument?

I ve read the doc for GetOptions but I can t seem to find what I need... (maybe I am blind) What I want to do is to parse command line like this myperlscript.pl -mode [sth] [inputfile] I can use ...

Object-Oriented Perl constructor syntax and named parameters

I m a little confused about what is going on in Perl constructors. I found these two examples perldoc perlbot. package Foo; #In Perl, the constructor is just a subroutine called new. sub new { #I ...

Where can I find object-oriented Perl tutorials? [closed]

A Google search yields a number of results - but which ones are the best? The Perl site appears to contain two - perlboot and perltoot. I m reading these now, but what else is out there? Note: I ve ...

热门标签