Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^2: Determining directory where script was called from

by Athanasius (Archbishop)
on Mar 13, 2019 at 06:08 UTC ( [id://1231194]=note: print w/replies, xml ) Need Help??


in reply to Re: Determining directory where script was called from
in thread Determining directory where script was called from

Hello nysus,

Glad $ENV{PWD} is working for you, but it doesn’t work for me on Windows:

15:51 >perl -wE "say $ENV{PWD};" Use of uninitialized value in say at -e line 1. 15:51 >

On the other hand, Cwd::getcwd() [or Cwd::cwd()] works fine for me, and is a more portable solution.

I tried using `getcwd()` to get the current working directory where the script was called from but it is returning undefined.

Was your call to the remote script something like this?

printf "\n%s\n", `perl remote_dir/remote_script.pl`;

If so, you’ll get undefined because backticks in list context returns a list (of lines; see perlop#Quote-Like-Operators). In scalar context it works as expected:

printf "\n%s\n", scalar `perl 1984_SoPW/remote.pl`;

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (6)
As of 2024-03-28 22:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found