开发者

uc before sort in map

开发者 https://www.devze.com 2023-01-28 20:47 出处:网络
map{ chomp; $isword{uc join \"\", sort /./g} .= \"$_+\" } <FH>; Generally, it uses items in 开发者_运维问答file, first sort, then uc, then add to hashmap.
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+'
        };
0

精彩评论

暂无评论...
验证码 换一张
取 消