uc before sort in map
map{ chomp; $isword{uc join "", sort /./g} .= "$_+" } <FH>;
Generally, it uses items in 开发者_运维问答file, first sort, then uc, then add to hashmap.
But I want to first uc, then sort.
Does any one know how to do it?
In keeping with the spirit of terseness you have achieved:
map{ chomp; $isword{join "", uc =~ sort /./g} .= "$_+" } <FH>;
Have a try with:
#!/usr/bin/perl
use 5.10.1;
use strict;
use warnings;
use Data::Dumper;
my %isword;
map{ chomp; my $c=$_; $_=uc$_; $isword{join "", sort /./g} .= "$c+" } <DATA>;
say Dumper \%isword;
__DATA__
cbA zyx
DEF tuv
Ghi PQr
Output:
$VAR1 = {
' GHIPQR' => 'Ghi PQr+',
' DEFTUV' => 'DEF tuv+',
' ABCXYZ' => 'cbA zyx+'
};
精彩评论