demichi has asked for the wisdom of the Perl Monks concerning the following question:
I have the following code.
use strict; use warnings; use File::Basename; my $script_dirname = dirname(__FILE__); print "dirname: $script_dirname\n";
When I run the script I get the following output:
C:\Data\scripting\misc>path_test.pl dirname: C:\Data\scripting\misc C:\Data\scripting\misc>
This is what I expect. I get the full path of the directory. All is good.
However when I run the script with the interpreter I get the following:
C:\Data\scripting\misc>perl path_test.pl dirname: . C:\Data\scripting\misc>
I just get the "." for the current directory.
Why is this the case? How can I always get easily the full path of the directoy where my script is running - no matter how the user calls the script?
(It must work on Windows and would be nice if this also runs on Unix).
Thanks for your help.
regards deMichi
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Windows - dirname(__FILE__)
by demichi (Beadle) on Apr 11, 2014 at 11:51 UTC | |
|
Re: Windows - dirname(__FILE__)
by choroba (Cardinal) on Apr 11, 2014 at 12:31 UTC | |
|
Re: Windows - dirname(__FILE__) ( Path::Tiny::path(__FILE__)->realpath->parent
by Anonymous Monk on Apr 11, 2014 at 21:46 UTC | |
|
Re: Windows - dirname(__FILE__)
by fishy (Friar) on Apr 11, 2014 at 16:48 UTC | |
by aitap (Curate) on Apr 11, 2014 at 17:53 UTC |