How do I get the full path to a Perl script that is executing?

后端 未结 23 3058
情深已故
情深已故 2020-11-28 19:29

I have Perl script and need to determine the full path and filename of the script during execution. I discovered that depending on how you call the script $0 va

23条回答
  •  余生分开走
    2020-11-28 20:00

    use File::Basename;
    use Cwd 'abs_path';
    print dirname(abs_path(__FILE__)) ;
    

    Drew's answer gave me:

    '.'

    $ cat >testdirname
    use File::Basename;
    print dirname(__FILE__);
    $ perl testdirname
    .$ perl -v
    
    This is perl 5, version 28, subversion 1 (v5.28.1) built for x86_64-linux-gnu-thread-multi][1]
    

提交回复
热议问题