[첫화면으로]"Perl/SchwartzianTransform" 페이지의 변경 내역

마지막으로 [b]


현재 버전 . . . . (수정) 2012-2-11 12:25 am 수정한 사람: Raymundo
1 번째 수정본 . . . . 2007-5-29 3:39 pm 수정한 사람: Raymundo
 

변경사항 (가장 최근의 "일반적인 수정"부터) (소소한 수정)

-1,3 +1,5
== # Schwartzian Transform ==
예를 들어, 파일 이름의 목록을 가지고, 그 파일의 크기를 비교하여 오름차순으로 정렬한다고 할 때, 단순하게는 다음과 같이 작성할 수 있다.
{{{#!vim perl

-44,10 +46,29
          @unsorted;
}}}
== # Guttman Rosler Transform ==
한술 더 떠서, ST에서 무수한 익명 배열을 만드는 오버헤드를 피하고, sort에서 기본으로 제공하는 정렬 알고리즘을 사용하게 변환할 수 있다.<footnote([http://www.perlmonks.org/?node_id=145659 Advanced Sorting - GRT - Guttman Rosler Transform -- Advanced Sorting - GRT - Guttman Rosler Transform])>
{{{#!vim perl
my @words=qw(The time has come the Walrus said to speak of many things);
## 위 리스트를, 각 단어 내의 "e"또는 "E"의 갯수에 따라 정렬하는 경우
# ST
my @sorted=map { pop @$_ }
           sort{ $a->[0] <=> $b->[0] ||
                 $a->[1] cmp $b->[1] }
           map { [tr/eE/eE/,$_] } @words;
# GRT
my @sorted=map  { substr($_,4) }
           sort 
           map  { pack("LA*",tr/eE/eE/,$_) } @words;
}}}
<div class="comments">
<longcomments(100)>
----
<trackbackreceived>
</div>
----
[[컴퓨터분류]]