Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Short and easy way to write if...elsif syntax

by GrandFather (Sage)
on Aug 27, 2012 at 11:14 UTC ( #989962=note: print w/ replies, xml ) Need Help??


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
True laziness is hard work


Comment on Re: Short and easy way to write if...elsif syntax
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://989962]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (9)
As of 2015-07-03 06:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (48 votes), past polls