
public at khwilliamson
Nov 15, 2009, 11:27 AM
Post #1 of 2
(245 views)
Permalink
|
|
Re: User-defined case mappings; use static variable in Perl?
|
|
Rafael Garcia-Suarez wrote: > 2009/11/13 karl williamson <public [at] khwilliamson>: >> [snip] >> Which brings us to the topic of these user-defined case-changing mappings. >> I just haven't gotten around to figuring out how to tell if such a function >> is in existence or not. Currently, they must be in main::. Since this is a >> very obscure corner of the language, I'm deferring fixing it until later. >> Rafael gave me one hint about how to figure out if such a mapping function >> exists, but I haven't pursued it yet. I understand that Zefram has been >> working on lexically-scoped subroutines, so that could affect this. > > I agree with the deferring. Is anyone aware about some code using > user-defined case mappings, by the way ? > I can imagine them being used for Turkish and Azeri, where the standard is problematic, and the regular mappings are incorrect. I remember reading the archives of this list and seeing someone who was trying to get Perl to work for Turkish. I have been thinking somewhat of how to implement this. The problem is we don't want to slow down things for this very rare (maybe non-existent) use. Since this feature is based on global subroutines, I would think one could store in a static variable if the existence of such a subroutine has been looked for or not. Then it could be structured so that the normal flow had just one test added to check this static. For example, initialize the static to 0 for not-looked at yet; set it to something else on the first time the case function is called, say 1 if found no routine; and anything else if found a routine. There would have to be one variable for each of lc, uc, and ucfirst (since lcfirst uses the same case definitions as lc). Now, I'm not very familiar with Perl internals, so I'm asking. I would think we would not want to normally use statics just because of lexical scoping and threads. But in this case, there is no lexical scoping, and the user-defined subroutines would apply to all threads. So would a static variable be an ok thing to use here?
|