Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Difference between $0 and __FILE__

by pobocks (Chaplain)
on Sep 26, 2012 at 04:45 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2024-03-28 15:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found