News:

2023-03-15 Major improvements to the new Geolocation feature

Main Menu

Switch Case in user defined tag?

Started by StarGeek, April 19, 2015, 06:25:56 PM

Previous topic - Next topic

StarGeek

I'm trying to make a user defined tag that will return the name of a person depending upon the serial number of the camera.  I ended up using IF statements and that's fine, but I'm interested in learning where my mistake with SWITCH was.  Here's the code:

CopyrightBySerialNumber => {
Require => 'SerialNumber',
ValueConv => q{
switch ($val){
case '1234567890' { return "John Smith"; }
case '0987654321' { return "Terry Pratchett"; }
case '1234123412' { return "Neil deGrasse Tyson"; }
case '8008675309' { return "Albert Einstein"; }
}
return undef;
},
        },


Some but not all, perl examples I saw had use Switch; at the beginning and I tried adding that at various places in the config file, but it didn't change anything. 
* 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

I wasn't aware of a Perl 'switch' statement.  If there is one, I've never used it.

- 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

I was just going off of what I read here.   But if it's something of an oddity or an add on, nevermind then.  I just thought I was doing something wrong and wanted to figure out my error.
* 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).

Hayo Baan

Hi stargeek,

Wow, that article is for a really old version of Perl (5.8.8). There is no switch statement in current Perl. The only thing than comes close is the given/when construct see article at perldoc. However, that feature has gone back to the drawing board and is now marked as experimental (as is the smart match operator ~~) again (it used to be ok to use it from v5.10 up to v5.16).

Better stick to if/then/else for now I guess.
Hayo Baan – Photography
Web: www.hayobaan.nl

Phil Harvey

Hi Stargeek,

In your reference they use a special "Switch" module.  This module may well provide this functionality, but it isn't part of the language.

- 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: Hayo Baan on April 20, 2015, 01:51:32 AM
Wow, that article is for a really old version of Perl (5.8.8).

That leads to something I've wondered a few times.  What version of perl does the Windows executable use?
* 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 command will tell you:

exiftool exiftool.exe

:)

It is an old version because I had some problems with newer versions on Windows.

- 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

Wow, very cool.

Bundled Perl Version            : ActivePerl 5.8.7
* 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).