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

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

Replies are listed 'Best First'.
Re^4: Code blocks with ternary operator or trailing conditionals
by choroba (Cardinal) on Feb 09, 2014 at 13:28 UTC
    You can factour out the ->() part:
    (43 > $x ? sub { print 'Yes, '; print 'it is!'; } : sub { print 'No, '; print 'it is not!'; } )->();
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re^4: Code blocks with ternary operator or trailing conditionals
by puterboy (Scribe) on Feb 09, 2014 at 15:28 UTC
    LOL - somehow I'm not sure that this will make my code read shorter and cleaner... though creative... :)