Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

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'.

Replies are listed 'Best First'.
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?

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 cooling their heels in the Monastery: (5)
As of 2018-11-21 17:55 GMT
Find Nodes?
    Voting Booth?
    My code is most likely broken because:

    Results (246 votes). Check out past polls.