ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: jeff_k on February 18, 2021, 09:54:20 PM

Title: SubSecTimeOriginal and three digits
Post by: jeff_k on February 18, 2021, 09:54:20 PM
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!
Title: Re: SubSecTimeOriginal and three digits
Post by: StarGeek on February 18, 2021, 11:01:20 PM
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).$_
Title: Re: SubSecTimeOriginal and three digits
Post by: jeff_k on February 18, 2021, 11:38:52 PM
So elegant - thank you!
As an aside, is there a good source for learning this syntax? These are Perl expressions, correct?
Title: Re: SubSecTimeOriginal and three digits
Post by: Phil Harvey on February 19, 2021, 07:51:02 AM
Yes, these are all just Perl expressions, operating on the default Perl variable $_

- Phil
Title: Re: SubSecTimeOriginal and three digits
Post by: StarGeek on February 19, 2021, 10:27:26 AM
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 (https://perlmaven.com/) 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.
Title: Re: SubSecTimeOriginal and three digits
Post by: Phil Harvey on February 19, 2021, 10:44:02 AM
This is how I learned:

(https://exiftool.org/pics/perl.jpg) (https://www.amazon.com/Programming-Perl-Unmatched-processing-scripting/dp/0596004923/ref=sr_1_1?dchild=1&keywords=perl+programming)

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

- Phil
Title: Re: SubSecTimeOriginal and three digits
Post by: jeff_k on February 20, 2021, 10:31:37 PM
Much appreciated! I have some work to do...