Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

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

by Athanasius (Bishop)
on Aug 27, 2012 at 11:57 UTC ( #989972=note: print w/replies, xml ) Need Help??

in reply to Short and easy way to write if...elsif syntax

For the problem as given, the following simple approach may be useful:

#! perl use strict; use warnings; my @array = ('Mastering linux is a steep learning curve', 'Using Windows can be frustrating', 'Plan 9 is rarely seen'); print /linux/ ? "This is linux VM\n" : /Windows/ ? "This is a Windows VM\n" : "I have no idea what it is\n" for @array;


This is linux VM This is a Windows VM I have no idea what it is

See Conditional Operator. But note that this approach is not generally scalable for dealing with more complex conditions. And see the thread if statement confusion for the syntactic pitfalls.

Hope that helps,

Athanasius <°(((><contra mundum

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2019-06-19 20:52 GMT
Find Nodes?
    Voting Booth?
    Is there a future for codeless software?

    Results (89 votes). Check out past polls.

    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!