current path

J

Jochen Friedmann

Hello together,

how can I find the current path my Perlscript is started ?

Jochen
 
T

Thens

# how can I find the current path my Perlscript is started ?

I dont know what you meant by the current path.

If it is the current directory, you can get the current working
directory like this

use Cwd;
my $dir = cwd();

You can get the full path to the script name from the variable $0 and
then if you do a basename on it you can get the path to the directory
where the script is present.

example :
script : /home/abc/scripts.pl

#!/usr/bin/perl

use strict;
use warnings;
use File::Basename;
my $dir = File::basename($0);
 
J

Jürgen Exner

Jochen said:
how can I find the current path my Perlscript is started ?

Please define "current path".

If you are talking about the current working directory, then please have a
look at Cwd::cwd.
If you are talking about the location of the Perl script in your filesystem,
then please check $FindBin::Bin.
Or $0.

Either of them may or may not work for your specific requirements.

jue
 
R

Richard S Beckett

how can I find the current path my Perlscript is started ?


use Cwd;
my $pwd = cwd; $pwd =~ s!/!\\!g;
print "Current path is $pwd\n";
 
P

Paanwa

Perl is not CGI.

The OP made no mention of what environment his Perl program runs in...

Hi Tad,

Thanks for pointing this out. I've not yet seen an environment with ENV
can't return the script path - there are always exceptions. Can anyone tell
me if there are performance consideration in using ENV vs Cwd?

PAW
 
T

Tad McClellan

Paanwa said:
Hi Tad,

Thanks for pointing this out.


Is your Perl programming running in the CGI environment or is it not?

I've not yet seen an environment with ENV
can't return the script path -


I have no idea what you are talking about.

We have asked you before to clarify what you meant by "script path",
please try and do that.

I can't tell if you want the current working directory, or the
location of your program file in the filesystem, or the URL for
some CGI program.

Which one is it that you are trying to find?

There are potentially lots and lots of environment variables,
which one is it that you are talking about? I assumed it
was $ENV{PWD}...

there are always exceptions. Can anyone tell
me if there are performance consideration in using ENV vs Cwd?


Now I am even more confused about what it is that you are asking.

If you are asking about the "current working directory", then why
do you keep mentioning the location of the program file?

Where your program file exists in the filesystem is not related
to what your current working directory is.

We must understand what you are asking for before we can help
you find it.

Try again explaining what it is that you are asking for.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top