diff options
| author | Matthew Neleigh <matthew.neleigh@gmail.com> | 2022-04-24 14:53:35 -0400 |
|---|---|---|
| committer | Matthew Neleigh <matthew.neleigh@gmail.com> | 2022-04-24 14:53:35 -0400 |
| commit | 6b7a7f742bbe3b99cf9688d71e983bfc76a7dd0d (patch) | |
| tree | 87fd5d61806c5cbf234969759f93b2eadc6492b9 /challenge-161 | |
| parent | 9abc0cc42a70f7e3a13c066d97b092cb972db38a (diff) | |
| download | perlweeklychallenge-club-6b7a7f742bbe3b99cf9688d71e983bfc76a7dd0d.tar.gz perlweeklychallenge-club-6b7a7f742bbe3b99cf9688d71e983bfc76a7dd0d.tar.bz2 perlweeklychallenge-club-6b7a7f742bbe3b99cf9688d71e983bfc76a7dd0d.zip | |
new file: challenge-161/mattneleigh/perl/ch-1.pl
Diffstat (limited to 'challenge-161')
| -rwxr-xr-x | challenge-161/mattneleigh/perl/ch-1.pl | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/challenge-161/mattneleigh/perl/ch-1.pl b/challenge-161/mattneleigh/perl/ch-1.pl new file mode 100755 index 0000000000..4865ba4622 --- /dev/null +++ b/challenge-161/mattneleigh/perl/ch-1.pl @@ -0,0 +1,63 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use English; + +################################################################################ +# Begin main execution +################################################################################ + +my @words; + +# Examine all lines from STDIN... +while(<>){ + chomp; + + # Skip blank lines + next + if(m/^$/); + + # Split the line on whitespace and loop over + # each returned string... + WORD: + foreach(split(" ", $_)){ + if(length($_) > 1){ + # Word is more than one character long; + # examine it + foreach my $pos (1 .. length($_) - 1){ + # Break to the next word if a character + # has an ordinal value that isn't less + # than or equal to the one before it + next WORD + unless( + ord(substr($_, $pos - 1, 1)) + <= + ord(substr($_, $pos, 1)) + ); + } + # Got here- all the characters are + # in the right order; store the abecedarian + # word + push(@words, $_); + } else{ + # Word is single-character; + # automatically store it + push(@words, $_); + } + } +} + +# Print out the stored abecedarian words, sorted in +# descending order by length +if(@words){ + print(join("\n", sort({ length($b) <=> length($a) } @words)), "\n"); +} + +exit(0); +################################################################################ +# End main execution; subroutines follow +################################################################################ + + + |
