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!
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).$_
So elegant - thank you!
As an aside, is there a good source for learning this syntax? These are Perl expressions, correct?
Yes, these are all just Perl expressions, operating on the default Perl variable $_
- Phil
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.
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
Much appreciated! I have some work to do...