diff options
Diffstat (limited to 'challenge-266/sgreen/perl/ch-1.pl')
| -rwxr-xr-x | challenge-266/sgreen/perl/ch-1.pl | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/challenge-266/sgreen/perl/ch-1.pl b/challenge-266/sgreen/perl/ch-1.pl new file mode 100755 index 0000000000..b4a97be57c --- /dev/null +++ b/challenge-266/sgreen/perl/ch-1.pl @@ -0,0 +1,29 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use feature 'say'; +use experimental 'signatures'; + +sub main (@strings) { + my %freq = (); + + # Compute the frequency of each word + foreach my $string (@strings) { + foreach my $word ( split / /, $string ) { + ++$freq{$word}; + } + } + + # Return the word(s) that appear only once. + my @match = grep { $freq{$_} == 1 } keys %freq; + if ( scalar(@match) == 0 ) { + # If there is no result, show an empty string + say "('')"; + } + else { + say "('", join( "', '", @match ), "')"; + } +} + +main(@ARGV);
\ No newline at end of file |
