Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^2: Code blocks with ternary operator or trailing conditionals

by puterboy (Scribe)
on Feb 09, 2014 at 02:55 UTC ( #1074088=note: print w/ replies, xml ) Need Help??


in reply to Re: Code blocks with ternary operator or trailing conditionals
in thread Code blocks with ternary operator or trailing conditionals

Thanks - I am aware of 'do' -- just was hoping there was a way to 'do' it without it...


Comment on Re^2: Code blocks with ternary operator or trailing conditionals
Re^3: Code blocks with ternary operator or trailing conditionals
by AnomalousMonk (Abbot) on Feb 09, 2014 at 12:08 UTC
    ... a way to 'do' it without it...

    I wouldn't say this is a better way (in fact, as kcott has pointed out below,  if { ... } else { ... } syntax is better for what you seem to want than this or a do block), but it's a way:

    c:\@Work\Perl\monks>perl -wMstrict -le "my $x = 42; ;; sub { print qq{Hello }; print qq{world!}; }->() if 7 < $x; ;; 43 > $x ? sub { print qq{Yes, }; print qq{it is!}; }->() : sub { print qq{No, }; print qq{it is not!}; }->() ; " Hello world! Yes, it is!
      You can factour out the ->() part:
      (43 > $x ? sub { print 'Yes, '; print 'it is!'; } : sub { print 'No, '; print 'it is not!'; } )->();
      لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
      LOL - somehow I'm not sure that this will make my code read shorter and cleaner... though creative... :)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (11)
As of 2015-07-01 23:54 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 (25 votes), past polls