Perl コーディング初心者質問コーナー Part36
■ このスレッドは過去ログ倉庫に格納されています
0051nobodyさん
04/07/16 13:52ID:???こういう事を言いたいのかな?
#--- test1.p ---
my @str = ('1,,,,', ',,,,1', ',,1,,', '');
print 0 + @{[split /,/]} for @str; # 1530
print "\n";
print 1 + tr/,// for @str; # 5551
print "\n";
print 0 + (length && 1 + tr/,//) for @str; # 5550
#--- test2.p ---
use Benchmark;
our @str = ('foo,bar,baz', 'hoge,fuga,' x 5, ',,,,1', ',,1,,', '1,,,,', '');
timethese(-5, {
split => sub { my $n = @{[split /,/]} for @str },
tr => sub { my $n = 1 + tr/,// for @str },
length => sub { my $n = length && 1 + tr/,// for @str },
});
■ このスレッドは過去ログ倉庫に格納されています