Jay Savage wrote: > > On 7/26/06, Rob Dixon <[EMAIL PROTECTED]> wrote: > > [sarcasm snipped]
No sarcasm intended Jay, and also I'm not sure what you took that way. I corrected an error in the Perl in my original response and made what I thought was a fairly non-toxic remark about enhancing code not being necessarily useful. > > I think you missed my point. That wasn't meant to be some example of a > badly formed .ini file. It was meant toillustrate the point for people > who haven't thought about it before. It doesn't have anything to do > with file structure. Don't put that code in a file. Run it. or try > this: > > perl -e '$a="F"; print $a + 0" > > If it's not something you've tried before, the result might surprise you. Ah, I see. Yes, I'm sorry I thought you were pointing out that my code would include the dollar sign in the parameter name and the quotes around its value. But I'm not sure what I should expect to happen if I evaluate 'F' + 0. I'm certain though that if warnings are enabled I'll get told off for it ... Yes, I've just tried it and it says "Argument "F" isn't numeric in addition" which is fine. That's why we go on endlessly in this group about using strict and warnings in all code. > Apologies. I misread your code. Fair enough. I do that too. > Feel free to modify the code to suit whatever structure you want to > put it into, but hold onto this simple advice: If you want to get > numbers out of string, use a regex that looks for numbers, not one > that looks for "not white space". Implementation details are, as > always, left as an exercise for the reader. I think I agree in general, but I still claim that the code I wrote had no business knowing what sort of values were expected in the config file. > /\s*(\w+)\s*=\s*(\d+)/ gives you, in the words of the slogan, > "everything you want, and nothing you don't." I must say I prefer \w+ for the parameter name, but I can well imagine that one of my parameter values may one day be a URL or something equally vague. Thanks Jay, happy Perling, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>