Thread Ternärer Operator: ?: (13 answers)
Opened by Heromaster at 2006-02-24 19:43

FIFO
 2006-02-25 12:32
#63290 #63290
User since
2005-06-01
469 Artikel
BenutzerIn

user image
Noch eine interessante Anwendung des terzolinären Operators sind if-elsif-elsif-...-else-Konstrukte (kaskadierte ifs), die werden nämlich besonders bei kurzen Blöcken/Anweisungen sehr übersichtlich:

Code: (dl )
1
2
3
4
my $anrede = $name =~ /heinz-willi/i ? 'Hi!'
: $name =~ /könig/i ? 'Majestät!'
: $alter < 6 ? 'Pimpf'
: 'Guten Tag';


steht in DamianConway: Perl Best Practices (O'Reilly)
Everyone knows that debugging is twice as hard as writing a program in the first place. So if you're as clever as you can be when you write it, how will you ever debug it? -- Brian Kernighan: "The Elements of Programming Style"

View full thread Ternärer Operator: ?: