I'm trying to create a helper function to do some processing of list type tags and I can't figure out how to access the list separator value.
I'm using the NoDups helper function as a starting point
sub MyNoDups
{
my %seen;
my $sep = $advFmtSelf ? $$advFmtSelf{OPTIONS}{ListSep} : ', ';
my $new = join $sep, grep { !$seen{$_}++ } split /\Q$sep\E/, $_;
$_ = ($_[0] and $new eq $_) ? undef : $new;
}
Looking back through the code, I see that $advFmtSelf is assigned the value of $self. But in an small config like the above would be, using $self doesn't seem be available.
So in the my $sep line, how would I assign the ListSep if the above was the entire config file?
Right. Unfortunately $advFmtSelf is a local variable in Writer.pl. I'll make this a package variable so you can access it through $Image::ExifTool::advFmtSelf in version 12.85
- Phil
Good to know I wasn't missing something obvious. I did a lot of digging though my notes and other config files.
It really isn't terribly important, more of a proof of concept thing. Just in case you can see a better way to do it, I was trying to make the natural sorting (https://exiftool.org/forum/index.php?msg=83636) code into an actual helper function so it could be used more easily inline. Something like
"-subject<${subject;NaturalSort($_)}"
rather than join/sort/split
"-subject<${subject;$_=join '//', sort{natcomp} split '//'}"
Easier to use with -api filter as well
That sounds good, but you can avoid passing $_ as an argument as I have done with the other helper functions.
- Phil
Quote from: Phil Harvey on May 08, 2024, 10:53:17 AMThat sounds good, but you can avoid passing $_ as an argument as I have done with the other helper functions.
Yeah, that was my next step in figuring things out, as I have some helper functions that needed it to work and some that didn't. Just have to take the time to compare the code and see what I did wrong.
$_ comes along for free when you call a function. Just use it directly in the function.
- Phil