programming-examples/perl/Statement/Plural message.pl

10 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+', <>);
my $words = scalar (@words);
#ERROR!
my $message = "There ". ($words==1) ? "is" : "are". " $words word" . ($words == 1)?"" : "s". " in the text\n";
print $message;