Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
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
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?
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 romping around the Monastery: (9)
As of 2015-07-31 05:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (274 votes), past polls