SubSecTimeOriginal and three digits

Started by jeff_k, February 18, 2021, 09:54:20 PM

Previous topic - Next topic

jeff_k

I'm using the expression below (from other posts here) to add SubSecTimeOriginal to the filename and pad it to three digits.
However, it's not apparently padding the way I'd expected.
For example, where SubSecTimeOriginal = 23, it's adding '.230' to the filename, whereas I'd wanted '.023'.
- Am I interpreting the value of '23' correctly, first of all? (i.e. is that really 23 and not a string that really represents 230?)
- How would I change the expression to pad the way I'd expected to?

-filename<$datetimeoriginal.${subsectimeoriginal;$_.='0'x(3-length)}%-c.%e

Thanks!

StarGeek

The .= operator is the same as $_=$_.'0'x(3-length), takes the value of subsectimeoriginal and adds to the end as you found out.  What you want is to swap the positions, $_='0'x(3-length).$_
* 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).

jeff_k

So elegant - thank you!
As an aside, is there a good source for learning this syntax? These are Perl expressions, correct?

Phil Harvey

Yes, these are all just Perl expressions, operating on the default Perl variable $_

- 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

Quote from: jeff_k on February 18, 2021, 11:38:52 PM
As an aside, is there a good source for learning this syntax? These are Perl expressions, correct?

PerlMaven has been the site where I feel I've learned the most Perl.  IMO, it's been easier to understand than the Perl docs.

Otherwise, I'll google what I want to do in Perl and often there's a code snippet on StackOverflow that I can often drop into the command.
* 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).

Phil Harvey

This is how I learned:



(note that the author, Tom Christiansen, has contributed code to ExifTool)

- 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 ($).

jeff_k

Much appreciated! I have some work to do...