programming-examples/perl/Statement/Plural format and ternary operator.pl
2019-11-15 12:59:38 +01:00

8 lines
247 B
Perl

#!/usr/bin/perl
use warnings;
use strict;
my @words = split ('\s+', <>); #read some text and split on whitespace
my $words = scalar (@words);
print "There ", ($words == 1)?"is":"are"," $words word", ($words == 1)?"":"s"," in the text \n";