Re: Determine script full path.
- From: "Paul Lalli" <mritty@xxxxxxxxx>
- Date: 29 Dec 2006 05:00:36 -0800
tower.grv@xxxxxxxxx wrote:
In my Perl script I need to determine where this script is .
Ex.script.pl has full path /tmp/1/script.pl Whet it starts it must to
know where script file is (/tmp/1).
I have found the solution.
No you haven't.
use Cwd;
$dir = cwd();
"Cwd" stands for "current working directory". That is not necessarily
the same as the directory in which your script resides.
Put your script in /tmp/1, as you have it. Change to your own home
directory, and execute the script as /tmp/1/script.pl, and you will see
that your script assigns $dir to your home directory, not /tmp/1
The correct answer is to use the FindBin module, not the Cwd module:
$ cat temp/script.pl
#!/usr/bin/perl
use strict;
use warnings;
use Cwd;
use FindBin;
print "Cwd: ", cwd(), "\n";
print "FindBin: ", $FindBin::Bin, "\n";
__END__
$ temp/script.pl
Cwd: /home/plalli
FindBin: /home/plalli/temp
Paul Lalli
.
- References:
- Determine script full path.
- From: tower.grv@xxxxxxxxx
- Re: Determine script full path.
- From: tower.grv@xxxxxxxxx
- Determine script full path.
- Prev by Date: Re: Accessing the values of HoH
- Next by Date: Re: Deleting files remotely
- Previous by thread: Re: Determine script full path.
- Next by thread: Re: Determine script full path.
- Index(es):
Relevant Pages
|
|