apotheon has asked for the wisdom of the Perl Monks concerning the following question:
A common Ruby idiom involves creating all the classes and methods necessary for a given program and for other programs that might want to use them as in a library call, then in its own little section write the code that makes use of those classes and methods, creating something that works equally well as either a library or a stand-alone script. Thus, for a program that needs nothing but what's in this script/library you just execute the file as a stand-alone program. For a program that also needs other stuff, you can call the script/library as a library, ignore the program logic for running it as its own program, and just make use of the classes and methods in the file.
This is, in Ruby, accomplished by wrapping your stand-alone program logic in a conditional like so:
if __FILE__ == $0 # do stuff end
If my first paragraph didn't make any sense to the reader, I hope the example sets things straight. Anyway, I know there's a $0 in Perl that does the same thing as $0 in Ruby, but I'm not able to find an equivalent for __FILE__ anywhere. Does such a thing exist, as such? If not -- what would be the Perl equivalent idiom?
CopyWrite Chad Perrin