Microblogi: A very long article Wikipedia article on the orientation of toilet paper [7. kes klo 22:52] [V]

Sunnuntai, 17. syyskuuta 2006

Dirty Things to do in Perl

Käännös: [ Google ]

Kategoriat: [ ATK ]

I just wanted to rename a bunch of files so that the new names are numbers like 1, 2, 3, 4… I could have written a short script doing that, but I wanted to see if rename was able to do it. Well, this works:

rename 's/.*/sprintf "Image-%02d.png", ++$main::i/e' *.png

(The original story is much worse: I wrote main::$i which of course did not work, so I took a look at the rename script, and noticed that I could use a variable which is already defined. I chose $verbose, which is initialized to 0 normally, but to 1 when the -n option is in use, hence the need to write ++$verbose when used with -n or -v and $verbose++ otherwise. Then I wrote this story about it, and only after that I noticed my mistake…)

[ Postattu 17. syyskuuta 2006 klo 01.08 | ei kommenttia | ]

Trackback osoite

https://weber.fi.eu.org/blog/Informatique/dirty_things_to_do_in_perl.trackback

Kommentit

Ei kommenttia

Lisää kommentejä

Voit käyttää seuraavat HTML tagit: <p>, <br>, <em> <strong>, <pre>. URL:t jotka alkaavat http://-lla muuttuvat automatisesti hyperlinkkeiksi.

(harkinnanvarainen)
(harkinnanvarainen)


Tallena nimeni ja URL/s-posti ensi kerralle

11 - 7 =