Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Difference between $0 and __FILE__

by pobocks (Chaplain)
on Sep 26, 2012 at 04:45 UTC ( #995699=note: print w/ replies, xml ) Need Help??


in reply to Difference between $0 and __FILE__

__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.

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__.

Example code:

File 1 - firstfile

#!/usr/bin/perl -w use strict; print $0 . "\n"; print __FILE__ . "\n"; do 'filetwo';

File 2 - filetwo

#!/usr/bin/perl -w use strict; print $0 . "\n"; print __FILE__ . "\n";

It's simplistic, but should show the basic concept.

for(split(" ","tsuJ rehtonA lreP rekcaH")){print reverse . " "}print "\b.\n";


Comment on Re: Difference between $0 and __FILE__
Select or Download Code
Replies are listed 'Best First'.
Re^2: Difference between $0 and __FILE__
by solegaonkar (Beadle) on Sep 26, 2012 at 05:10 UTC
    That explains it! Thank you!!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://995699]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (11)
As of 2015-07-31 17:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (279 votes), past polls