Save runtime. Do the calculation once and then use a lookup: #! perl -slw
use strict;
my $lookup = join '', map{ chr( $_ / 255 * 100 ) } 0 .. 255;
print "$_ :: ", ord( substr $lookup, $_, 1 ) for 0 .. 255;
__END__
C:\test>junk99
0 :: 0 1 :: 0 2 :: 0
3 :: 1 4 :: 1 5 :: 1
6 :: 2 7 :: 2
8 :: 3 9 :: 3 10 :: 3
11 :: 4 12 :: 4
13 :: 5 14 :: 5 15 :: 5
16 :: 6 17 :: 6
18 :: 7 19 :: 7 20 :: 7
21 :: 8 22 :: 8
23 :: 9 24 :: 9 25 :: 9
26 :: 10 27 :: 10 28 :: 10
29 :: 11 30 :: 11
31 :: 12 32 :: 12 33 :: 12
34 :: 13 35 :: 13
36 :: 14 37 :: 14 38 :: 14
39 :: 15 40 :: 15
41 :: 16 42 :: 16 43 :: 16
44 :: 17 45 :: 17
46 :: 18 47 :: 18 48 :: 18
49 :: 19 50 :: 19
51 :: 20 52 :: 20 53 :: 20
54 :: 21 55 :: 21 56 :: 21
57 :: 22 58 :: 22
59 :: 23 60 :: 23 61 :: 23
62 :: 24 63 :: 24
64 :: 25 65 :: 25 66 :: 25
67 :: 26 68 :: 26
69 :: 27 70 :: 27 71 :: 27
72 :: 28 73 :: 28
74 :: 29 75 :: 29 76 :: 29
77 :: 30 78 :: 30 79 :: 30
80 :: 31 81 :: 31
82 :: 32 83 :: 32 84 :: 32
85 :: 33 86 :: 33
87 :: 34 88 :: 34 89 :: 34
90 :: 35 91 :: 35
92 :: 36 93 :: 36 94 :: 36
95 :: 37 96 :: 37
97 :: 38 98 :: 38 99 :: 38
100 :: 39 101 :: 39
102 :: 40 103 :: 40 104 :: 40
105 :: 41 106 :: 41 107 :: 41
108 :: 42 109 :: 42
110 :: 43 111 :: 43 112 :: 43
113 :: 44 114 :: 44
115 :: 45 116 :: 45 117 :: 45
118 :: 46 119 :: 46
120 :: 47 121 :: 47 122 :: 47
123 :: 48 124 :: 48
125 :: 49 126 :: 49 127 :: 49
128 :: 50 129 :: 50 130 :: 50
131 :: 51 132 :: 51
133 :: 52 134 :: 52 135 :: 52
136 :: 53 137 :: 53
138 :: 54 139 :: 54 140 :: 54
141 :: 55 142 :: 55
143 :: 56 144 :: 56 145 :: 56
146 :: 57 147 :: 57
148 :: 58 149 :: 58 150 :: 58
151 :: 59 152 :: 59
153 :: 60 154 :: 60 155 :: 60
156 :: 61 157 :: 61 158 :: 61
159 :: 62 160 :: 62
161 :: 63 162 :: 63 163 :: 63
164 :: 64 165 :: 64
166 :: 65 167 :: 65 168 :: 65
169 :: 66 170 :: 66
171 :: 67 172 :: 67 173 :: 67
174 :: 68 175 :: 68
176 :: 69 177 :: 69 178 :: 69
179 :: 70 180 :: 70 181 :: 70
182 :: 71 183 :: 71
184 :: 72 185 :: 72 186 :: 72
187 :: 73 188 :: 73
189 :: 74 190 :: 74 191 :: 74
192 :: 75 193 :: 75
194 :: 76 195 :: 76 196 :: 76
197 :: 77 198 :: 77
199 :: 78 200 :: 78 201 :: 78
202 :: 79 203 :: 79
204 :: 80 205 :: 80 206 :: 80
207 :: 81 208 :: 81 209 :: 81
210 :: 82 211 :: 82
212 :: 83 213 :: 83 214 :: 83
215 :: 84 216 :: 84
217 :: 85 218 :: 85 219 :: 85
220 :: 86 221 :: 86
222 :: 87 223 :: 87 224 :: 87
225 :: 88 226 :: 88
227 :: 89 228 :: 89 229 :: 89
230 :: 90 231 :: 90 232 :: 90
233 :: 91 234 :: 91
235 :: 92 236 :: 92 237 :: 92
238 :: 93 239 :: 93
240 :: 94 241 :: 94 242 :: 94
243 :: 95 244 :: 95
245 :: 96 246 :: 96 247 :: 96
248 :: 97 249 :: 97
250 :: 98 251 :: 98 252 :: 98
253 :: 99 254 :: 99
255 :: 100
And if you'd prefer less zeros, or more 100s, then fudge it. (Add 0.5).
With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
In the absence of evidence, opinion is indistinguishable from prejudice.
Suck that fhit
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|