"Simon Strandgaard" <neoneye / adslhome.dk> schrieb im Newsbeitrag news:20040430175242.7aa717ad.neoneye / adslhome.dk... > "Robert Klemme" <bob.news / gmx.net> wrote: > > "Kent Dahl" <kentda+news / stud.ntnu.no> schrieb im Newsbeitrag > > news:c6tmj9$58n$1 / orkan.itea.ntnu.no... > > > Robert Klemme wrote: > > > > Where would you expect it to reside? Maybe the best solution is > > > > > > > > $0 : path as used for invocation > > > > __FILE__: abs path to current file > > > > > > > > Then I agree. :-) Any objections? Does this break existing code? > > > > > > Wouldn't this break the idiom of using > > > > > > if __FILE__ == $0 then > > > #... > > > end > > > > > > to make a file both require-able and executable? > > > I know I use it frequently. > > > > Yeah, I think it is used quite frequently. Darn. The only ad hoc > > sulution to this that occurs to me is to override __FILE__#== and $0#== to > > repair this. Now this starts getting ugly... Simon? > > Agree, the line 'if __FILE__ == $0' is indeed ugly > > There is 4 things wrong with it: > > A) $0 is a global variable, with a very short name, > not selfexplaining. .... but known from the earlies shell scripts. > B) people sometimes write to $0, when they want to tell > ps or top, what the process are currently doing. > this is fragile, I have been hit by it one time. Yep. > C) __FILE__ and $0 is relative paths. > this is fragile, I have been hit by it more than one time. They are not always relative, it depends on the invocation. > D) making the comparison, seems kludgy. Well, sort of. > I remember it took me forever to figure these things out. > > > I think its time to rethink __FILE__ and get rid of $0. I certainly disagree here: $0 never changes automatically during the lifetime of a script while __FILE__ reflects the current file. That's an important distinction in the light of require and load. Just imagine a help module that automatically prints invocation hints... Regards robert