Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Determining directory where script was called from

by nysus (Vicar)
on Mar 13, 2019 at 02:42 UTC ( #1231193=note: print w/replies, xml ) Need Help??


in reply to Determining directory where script was called from

NVM. It's in $ENV{PWD};

$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar";
$nysus = $PM . ' ' . $MCF;
Click here if you love Perl Monks

  • Comment on Re: Determining directory where script was called from

Replies are listed 'Best First'.
Re^2: Determining directory where script was called from
by Athanasius (Bishop) on Mar 13, 2019 at 06:08 UTC

    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
Node Status?
node history
Node Type: note [id://1231193]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2019-06-27 02:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Is there a future for codeless software?



    Results (111 votes). Check out past polls.

    Notices?