Main Menu

Perl for beginners

Started by Tarn, February 28, 2013, 10:40:39 AM

Previous topic - Next topic

Tarn

Could someone recommend a source for me to learn the basics of Perl?

At this point I need something basic, succinct, and to the point; down and dirty as it were. Most of the stuff I've found, so far, starts to give a definition, but ends up going into so much detail before getting to the point, that I get lost. The other problem is that most of them use the verbiage of a 25 year Perl veteran... which is a bit over my head at this point.

So something that says "$", does this; "^", does that. Would be best. Once I get the basics, I can use "$", does this, unless there is a "~" in any file on your hard drive, that was accessed in the last "/nn/" days, unless you add "(^\*~~P-??/" to your third coven stack.

KISS (Keep It Simple, Stupid, or Keep It Simple for Stupid)

Thanks in advance.

Phil Harvey

Hi Tarn,

It would be helpful to know what you want to do.  You don't need to know Perl to be able to use ExifTool.  The only time Perl comes into things is with some of the advanced ExifTool features that most people don't use anyway.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Tarn

Hi Phil

I did a little programming in Figfourth long ago. So I learned to accept that something works, without understanding why it works. Yet, I still would like to know what "-filename<${datetimeoriginal}-${filename;s/.*(\d{4}\.)/$1/}" -d ... means. Things like why is the double quote mark at the very beginning of "-filename<$Tag" in this case, but before the redirect in other cases; such as -filename"<$...? Why do some arguments have "(" braces while other have "[" and some have "{"? Things like that.

I want to understand the code that I'm using. And, eventually, be able to use the more advanced features of Exiftool. For example, the code you gave me to correct the "mystery tag" worked great, with the exception of about four files. Playing around with what you gave me, I figure out how to re-build the corrupted information in a couple of tags in those files. When I first got ExifTool, I tried the -overwrite_original option. It still produced the "_original" files. But that was "monkey see - monkey do"; I had no idea of what I was doing, or what I was doing wrong. Now, understanding the syntax a little better, it's working just like it should. And as I understand more about Perl, I can read over a line that didn't work, and pick out some of my mistakes and typo's and correct them on my own.

I would like to (some day) be able to copy files out a large group, and re-name them according to what lens they were shot with, or what f/stop I was using, or even go so far as to pick out files that were shot with different lenses, but at the same focal length and f/stop. And other useful things.

To sum it up, I want to be able to understand what I'm seeing (as far as the code goes); be able to use the more advanced features of Exiftool, and (maybe) be able to figure out how to do things without having to bother you all the time. 

So, something like "A Moron's guide to Perl" would be a good start.  Just the basics for now.

Phil Harvey

Well, you have mentioned one of the very few places where Perl actually shows through... in the advanced formatting expression.  In an argument like this: "-DSTTAG<${SRCTAG;EXPR}", the EXPR part is pure perl.  The rest is the syntax of the exiftool application options.  For this, read the -tagsFromFile section of the exiftool application documentation.

To understand what can go in the Perl EXPR, you do need to know Perl.  Your example uses a substitution expression (s/REPLACE THIS/WITH THIS/).  Look up Perl regular expressions to understand these.  (These, BTW, are the single most complicated part of the Perl language, so I wouldn't recommend these for the faint of heart.)  The best Perl reference I can give is O'Reilly's Perl Programming Language, and is the only reference that I use, but it is definitely more than you requested.

You asked specifically about braces.  In Perl regular expressions, you can choose your own brace, so all of these are equivalent:

s/REPLACE THIS/WITH THIS/
s(REPLACE THIS)(WITH THIS)
s=REPLACE THIS=WITH THIS=
s|REPLACE THIS|WITH THIS|
s[REPLACE THIS][WITH THIS]
s*REPLACE THIS*WITH THIS*
s{REPLACE THIS}{WITH THIS}


Being able to use different quotes comes in very handy to avoid having to escape characters in the contained expressions.  (ie. If I use slashes as delimiters, then any slash in the expression must be escaped.  This leads to "leaning toothpick syndrome"... for example,  s/\//\\/g replaces all forward slashes with backward slashes, but the forward slash and backward slash inside the expression had to be escaped with a backward slash each.  So in this case, something like s(/)(\\)g may be easier to read.)

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

StarGeek

With regards to Regular Expressions, I found http://www.regular-expressions.info/ to be a very helpful website.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

Tarn

Quote from: StarGeek on March 01, 2013, 04:17:31 PM
With regards to Regular Expressions, I found http://www.regular-expressions.info/ to be a very helpful website.

Thanks. I bookmarked it so I can go back to it. It looks like it has some valuable info there.