Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
Re: Substitution problem.by snax (Hermit) |
on Nov 25, 2000 at 20:13 UTC ( [id://43314]=note: print w/replies, xml ) | Need Help?? |
Why don't you try to do this more "all at once"? First, note that tr/// is the right tool for single character substitution lists -- it's heavily optimized for this kind of thing. Second, it seems to me that your $count variable may be redundant. Why not make one hash with keys the "old" values and the values the "new" values -- that sounds odd, but basically: ...but do this where you are building %array1 and %array2 so you don't need to use $count or the array hashes at all. Aside: in perl's common parlance, "array" typically refers to an integer indexed object like you are using your hashes above, but the hash construct is much more flexible (and more expensive to use in terms of resources). Anyway, with a %replacements hash you can then do: This does all your replacements with one evaluation. Again, note that this is really only appropriate when you need to replace more than single characters.
In Section
Seekers of Perl Wisdom
|
|