Accessing ListSep in bare bones config file

Started by StarGeek, May 05, 2024, 03:58:39 PM

Previous topic - Next topic

StarGeek

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?
* 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

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
...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

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 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
* 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

That sounds good, but you can avoid passing $_ as an argument as I have done with the other helper functions.

- 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: 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.
* 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

$_ comes along for free when you call a function.  Just use it directly in the function.

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