Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Warning while using ternary operator

by mward (Initiate)
on Dec 17, 2013 at 11:46 UTC ( #1067458=note: print w/ replies, xml ) Need Help??


in reply to Warning while using ternary operator

If what you really want is:

  • Assign "hello"."world" to the hash when ($i eq 'one')
  • Do nothing when ($i ne 'one')

Then one way to achieve this is:

($i eq 'one') ? $hash->{'name'} = "hello"."world" : 0;

Executing "0" does not give a warning, unlike executing 'nothing'.


Comment on Re: Warning while using ternary operator
Download Code
Re^2: Warning while using ternary operator
by tobyink (Abbot) on Dec 17, 2013 at 11:51 UTC

    Though that would be a hell of a lot more readable as:

    $hash->{'name'} = "hello"."world" if $i eq 'one';
    use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2014-10-25 05:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (142 votes), past polls