Blob


1 #!/usr/bin/perl
3 # Using a Schwartzian Transform, read a list of words and sort them in
4 # "dictionary order." Dictionary order ignores all capitalization and
5 # internal punctuation. Hint: The following transformation might be useful:
6 #
7 # my $string = 'Mary Ann';
8 # $string =~ tr/A-Z/a-z/;
9 # $string =~ tr/a-z//cd;
10 # print $string;
12 # Be sure you don't mangle the data! If the input includes 'the Professor'
13 # and 'The Skipper', the output should have them listed in that order, with
14 # that capitalization.
16 use v5.24;
17 use warnings;
18 use strict;
19 use utf8;
21 chomp(my @lines = <>);
23 my @sorted =
24 map { $_->[0] }
25 sort { $a->[1] cmp $b->[1] }
26 map {
27 my $str = $_;
28 $str =~ tr/A-Z/a-z/;
29 $str =~ tr/a-z//cd;
30 [$_, $str]
31 } @lines;
32 print join "\n", @sorted;