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 (Archbishop) 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,