Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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:

$ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 20.04.2 LTS Release: 20.04 Codename: focal $

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.

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 renaming all files in a directory. 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.

I tried one of the answers I hadn't used before:

ls | perl -nle 'BEGIN {$counter=0}; $old=$_;$new="image"."$counter"." +.jpg"; +rename($old,$new);$counter++;' $

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 Util's talk at 2020 perl conference, which helped me understand how people "get there on the command line."

$ 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++;' $

and voila...

$ 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 $

Another modification gets my captions looking all uniform, so I know I've got a bijection going:

ls | perl -nle 'BEGIN {$counter=0}; $old=$_;$new="caption"."$counter". +".txt"; +rename($old,$new);$counter++;'
$ 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 $

Now I know that my data will be well-conditioned for use by other scripts to get it onto the net.

This was just my day in having perl making something easier....

In reply to Renaming all files in a directory by Aldebaran

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (5)
As of 2022-12-09 23:37 GMT
Find Nodes?
    Voting Booth?

    No recent polls found