Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

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";

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?

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2022-12-10 05:32 GMT
Find Nodes?
    Voting Booth?

    No recent polls found