Control Flow Patterns
Ternary and Defaulting
The ternary operator chooses one expression, and // supplies a default for undef.
Ternary and Defaulting
ternary_default.pl
use strict;
use warnings;
my $count = ;
my $label = $count == 1 ? "item" : "items";
my $owner = undef;
my $display_owner = $owner // "unassigned";
print "count=$count\n";
print "label=$label\n";
print "owner=$display_owner\n";
use strict;
use warnings;
my $count = ;
my $label = $count == 1 ? "item" : "items";
my $owner = undef;
my $display_owner = $owner // "unassigned";
print "count=$count\n";
print "label=$label\n";
print "owner=$display_owner\n";
use strict;
use warnings;
my $count = ;
my $label = $count == 1 ? "item" : "items";
my $owner = undef;
my $display_owner = $owner // "unassigned";
print "count=$count\n";
print "label=$label\n";
print "owner=$display_owner\n";
ternary
A ternary expression uses `condition ? true_value : false_value`.