Perl ワンライナーで遊んだメモ

  • シリアル
% echo 'To be or not to be, that is the question'| perl -lane 'map{s/,//g;$hash{lc($_)}++} @F;foreach(keys %hash){print qq/$_:$hash{$_}/}'
the:1
that:1
not:1
is:1
question:1
to:2
or:1
be:2
  • map だけパラレル?
% echo 'To be or not to be, that is the question' > input_1.txt
% perl -MFile::Copy=copy -e 'for(2..10){copy "input_1.txt", "input_$_.txt"}' 
% find . -type f -name 'input_*' -print0|{xargs -0 -P 3 -n1 perl -i.org -lane 'map{s/,//g;$hash{lc($_)}++} @F;print "$_:$hash{$_}" foreach(keys %hash)'} && perl -F: -lane '$hash{$F[0]}+=$F[1];END{print "$_:$hash{$_}" foreach(keys %hash)}' input_*.txt
question:10
the:10
to:20
or:10
be:20
not:10
that:10
is:10