# No.55 Perl Sample (code key - 49) # Programs: revsersive alphabetical order (単語の末尾からのアルファベット順にする) # Tomonori Nagano # Last Update: January 18, 2008 # # This file is encoded in Unicode (UTF-8). If you see gibberish characters, # please re-encode the file in utf-8. # while(<>){ s/([^\- a-zA-Z0-9])/ \1 /g ; # a negative definition of punctuation @words = split (" ",lc($_)); foreach (@words) { next if (/[^a-zA-Z]/) ; # skip if not alphabet $rWord = reverse($_) ; $rev{$rWord} = $_ ; } } foreach my $key (sort keys %rev) { push (@revAlph,$rev{$key}) ; } foreach my $key (sort {$rev{$a} cmp $rev{$b}} keys %rev) { push (@alph,$rev{$key}) ; } printf ("%15s %15s", alphabetical,Rev_alphabetical) ; print "\n" ; for (0..$#alph) { printf ("%15s %15s", $alph[$_],$revAlph[$_]) ; print "\n" ; }