in reply to Short and easy way to write if...elsif syntax
Depending on your real application, it may be that a dispatch table would serve you well. Consider:
use strict; use warnings; my %oss = (linux => \&isLinux, Windows => \&isWindows, undef => \&isOt +her); my @array = qw(linux Windows wibble); exists $oss{$_} ? $oss{$_}->() : $oss{undef}->() for @array; sub isLinux { print "This is linux VM" . "\n"; } sub isWindows { print "This is a Windows VM" . "\n"; } sub isOther { print "I have no idea what it is" . "\n"; }
Prints:
This is linux VM This is a Windows VM I have no idea what it is
|
|---|