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;
In reply to Re^3: Which is more faster? While or tr///
by JavaFan
in thread Which is more faster? While or tr///
by tej
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |