programming-examples/perl/Statement/Plural format and ternary operator.pl

8 lines
247 B
Perl
Raw Normal View History

2019-11-15 12:59:38 +01:00
#!/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";