perlquestion
apotheon
<p>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.</p>
<p>This is, in Ruby, accomplished by wrapping your stand-alone program logic in a conditional like so:</p>
<code>
if __FILE__ == $0
# do stuff
end
</code>
<p>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 <code>$0</code> in Perl that does the same thing as <code>$0</code> in Ruby, but I'm not able to find an equivalent for <code>__FILE__</code> anywhere. Does such a thing exist, as such? If not -- what would be the Perl equivalent idiom?</p>
<div class="pmsig"><div class="pmsig-397229">
<p align="left"><table width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td align="left"><table border="0" cellpadding="0" cellspacing="0" bgcolor="#000000"><tr><td align="left"><font color="#ffffff" size="2"><b>print substr("Just another Perl hacker", 0, -2);</b></font></td></tr></table></td>
<td align="right">- <font color="#0000ff">a</font><font color="#3355ff">p</font><font color="#6688ff">o</font><font color="#99bbff">t</font><font color="#99bbff">h</font><font color="#6688ff">e</font><font color="#3355ff">o</font><font color="#0000ff">n</font>
<br />
[http://ccd.apotheon.org|CopyWrite] Chad Perrin</td></tr></table></p>
</div></div>