Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Warning while using ternary operator

by mward (Initiate)
on Dec 17, 2013 at 11:46 UTC ( [id://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 (Canon) 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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1067458]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (6)
As of 2024-04-23 18:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found