perlmeditation
Aldebaran
<p>I'm so relieved to be back at my keyboard, with a roof over my head, fridge full of food, and plentiful water of varied temperature. I was feeling kind of stuck because I had a repository that I had downloaded that didn't have the proper credentials, and it was preventing updating. I got that all cleared away, so now I have:
</p>
<c>$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.2 LTS
Release: 20.04
Codename: focal
$
</c>
<p>One of the first things I'll do is create a webpage describing the trip, and that is going to require that a bunch of odd images gets herded to the net, with an exact number of corresponding captions. For this task, I find that I can really economize on GUI events with perl and a little skill on the command line.</p>
<p>But I'm one of those guys who would make every mistake in the book if I started at square one. I know that I had a thread some time back called [id://975506]. I tried to search for this with keywords but had to resort to scrolling through my writeups back to 2012. I was gonna complain that the search didn't work. However, I had searched for the word 'rename' not 'renaming', and I realize that the problem is not with the software.</p>
<p>I tried one of the answers I hadn't used before:</p>
<c> ls | perl -nle 'BEGIN {$counter=0}; $old=$_;$new="image"."$counter".".jpg";
+rename($old,$new);$counter++;'
$
</c>
<p>That command didn't work at first, but I could get my way to one that did because what exists between single quotations is lexical perl that I understand. And gosh, I've been pretty diligent about studying this including taking in [https://www.youtube.com/watch?v=wZZtrtoTjt4&t=302s|Util's talk at 2020 perl conference,] which helped me understand how people "get there on the command line."</p>
<c>
$ ls | perl -nle 'BEGIN {$counter=0}; $old=$_;$new="image"."$counter"."jpg";
> +rename($old,$new);$counter++;'
$ ls | perl -nle 'BEGIN {$counter=0}; $old=$_;$new="image"."$counter".".jpg";
+rename($old,$new);$counter++;'
$
</c>
<p>and voila...</p>
<c>$ pwd
/home/hogan/6.scripts.personal/1.umatilla.1./template_stuff/aimages
$ ls
image0.jpg image12.jpg image15.jpg image3.jpg image6.jpg image9.jpg
image10.jpg image13.jpg image1.jpg image4.jpg image7.jpg
image11.jpg image14.jpg image2.jpg image5.jpg image8.jpg
$
</c>
<p>Another modification gets my captions looking all uniform, so I know I've got a bijection going:</p>
<c>ls | perl -nle 'BEGIN {$counter=0}; $old=$_;$new="caption"."$counter".".txt";
+rename($old,$new);$counter++;' </c>
<c>$ pwd
/home/hogan/6.scripts.personal/1.umatilla.1./template_stuff/captions
$ ls
caption0.txt caption13.txt caption2.txt caption6.txt
caption10.txt caption14.txt caption3.txt caption7.txt
caption11.txt caption15.txt caption4.txt caption8.txt
caption12.txt caption1.txt caption5.txt caption9.txt
$
</c>
<p>Now I know that my data will be well-conditioned for use by other scripts to get it onto the net.</p>
<p>This was just my day in having perl making something easier....</p>