in reply to Re^2: Which is more faster? While or tr///
in thread Which is more faster? While or tr///
Whole code looks likeThat makes a tr/// solution a non-candidate, doesn't it?while ($string=~m{<(ths|193)>|\.}g) { $count=$count+($tbsz * 0.25); }
I'd probably go for something like:
You may want to consider replacing the (.) with ($charclass), where:my %factor; $factor{ths} = $factor{193} = 0.25; $factor{ems} = $factor{194} = 0.5; $factor{ens} = $factor{195} = 1; $factor{W} = $factor{' '} = $factor{"\n"} = $factor{"\t"} = ... = 1; $factor{w} = $factor{'('} = $factor{')'} = 0.84375; .... my $count; while (/(?|<([A-Za-z0-9]+)>|(.))/g) { no warnings 'uninitialized'; $count += $factor{$1}; } $count *= $tbsz;
Whether that makes a difference depends on your data set.my $charclass = join "", grep {1 == length} keys %factor;
|
|---|