Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: Warning while using ternary operator

by mward (Initiate)
on Dec 17, 2013 at 06: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'.

Replies are listed 'Best First'.
Re^2: Warning while using ternary operator
by tobyink (Abbot) on Dec 17, 2013 at 06: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?

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2018-09-20 00:24 GMT
Find Nodes?
    Voting Booth?
    Eventually, "covfefe" will come to mean:

    Results (170 votes). Check out past polls.

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