開発環境
- OS X Lion - Apple(OS)
- BBEdit - Bare Bones Software, Inc.(Text Editor)
- Script言語:Perl
その他参考書籍
3.
コード(BBEdit)
sample.pl
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use 5.016;
binmode STDOUT, ':utf8';
binmode STDIN, ':utf8';
use Benchmark qw(:all);
my @words = qw(e a d b c E A D B C);
my @sorted = map {$_->[0]} sort {$a->[1] cmp $b->[1]} map {
my $string = $_;
$string =~ tr/A-Z/a-z/;
$string =~ tr/a-z//cd;
[$_, $string]
} @words;
print map {"$_\n"} @sorted;
入出力結果(Terminal)
$ ./sample.pl a A b B c C d D e E $
ちなみにJavaScriptの場合。
コード(BBEdit)
var words = ['e','a','d','b','c','E','A','D','B','C'];
words.sort( function( a, b ) {
a = (a).toString().toUpperCase();
b = (b).toString().toUpperCase();
if (a < b){
return -1;
} else if(a > b){
return 1;
} else {
return 0;
}
});
$('#pre0').text(words);
pythonの場合。
sample.py
コード(BBEdit)
#!/usr/bin/env python3.3 #-*- coding: utf-8 -*- words = ['e','a','d','b','c','E','A','D','B','C'] words.sort(key=lambda x: str(x).upper()) print(words)
入出力結果(Terminal)
$ ./sample.py ['a', 'A', 'b', 'B', 'c', 'C', 'd', 'D', 'e', 'E'] $
0 コメント:
コメントを投稿