<?xml version="1.0" encoding="windows-1252"?>
<node id="995699" title="Re: Difference between $0 and __FILE__" created="2012-09-26 00:45:13" updated="2012-09-26 00:45:13">
<type id="11">
note</type>
<author id="572803">
pobocks</author>
<data>
<field name="doctext">
&lt;p&gt;__FILE__ is the file name that the __FILE__ token is in, and $0 is a variable containing the name of the program, as given to the shell.&lt;/p&gt;  

&lt;p&gt;They can most certainly be different - one case that comes to mind is a __FILE__ token in a library called by your program, but there are many others, particularly since you can assign to $0 (with varying effects on different OS), but you can't meaningfully assign to __FILE__.&lt;/p&gt;

&lt;p&gt;Example code:&lt;/p&gt;
&lt;p&gt;&lt;b&gt;File 1 - firstfile&lt;/b&gt;&lt;/p&gt;
&lt;code&gt;
#!/usr/bin/perl -w
use strict;

print $0 . "\n";
print __FILE__ . "\n";

do 'filetwo';
&lt;/code&gt;
&lt;p&gt;&lt;b&gt;File 2 - filetwo&lt;/b&gt;&lt;/p&gt;
&lt;code&gt;
#!/usr/bin/perl -w
use strict;

print $0 . "\n";
print __FILE__ . "\n";
&lt;/code&gt;
&lt;p&gt;It's simplistic, but should show the basic concept.&lt;/p&gt;
&lt;!-- Node text goes above. Div tags should contain sig only --&gt;
&lt;div class="pmsig"&gt;&lt;div class="pmsig-572803"&gt;

&lt;code&gt;for(split(" ","tsuJ rehtonA lreP rekcaH")){print reverse . " "}print "\b.\n";&lt;/code&gt;
&lt;/div&gt;&lt;/div&gt;</field>
<field name="root_node">
995692</field>
<field name="parent_node">
995692</field>
</data>
</node>
