How to directly get the script-path.

Discussion in 'Perl Misc' started by ZZT, Jun 21, 2004.

  1. ZZT

    ZZT Guest

    Hi,

    I'd like to get the directory of the currently running script (not the
    working directory) but without concat constructs with $0 and getcwd().
    Is there an easy way, an internal or ENV var?

    thanks a lot
     
    ZZT, Jun 21, 2004
    #1
    1. Advertisements

  2. ZZT

    Sam Holden Guest

    On Mon, 21 Jun 2004 14:05:15 +0200, ZZT <> wrote:
    > Hi,
    >
    > I'd like to get the directory of the currently running script (not the
    > working directory) but without concat constructs with $0 and getcwd().
    > Is there an easy way, an internal or ENV var?


    perldoc -q "directory my program lives in"

    --
    Sam Holden
     
    Sam Holden, Jun 21, 2004
    #2
    1. Advertisements

  3. ZZT

    Paul Lalli Guest

    On Mon, 21 Jun 2004, ZZT wrote:

    > Hi,
    >
    > I'd like to get the directory of the currently running script (not the
    > working directory) but without concat constructs with $0 and getcwd().
    > Is there an easy way, an internal or ENV var?
    >
    > thanks a lot



    You might want a combination of File::Basename::dirname and
    File::Spec::rel2abs. Something like this, perhaps:

    [untested]
    #!/usr/bin/perl
    use strict;
    use warnings;
    use File::Basename;
    use File::Spec;

    my $dir = File::Spec->rel2abs(dirname($0));

    print "$dir\n";


    Paul Lalli
     
    Paul Lalli, Jun 21, 2004
    #3
  4. On Mon, 21 Jun 2004 14:05:15 +0200, ZZT <> wrote:
    > I'd like to get the directory of the currently running script (not the
    > working directory) but without concat constructs with $0 and getcwd().
    > Is there an easy way, an internal or ENV var?


    perldoc FindBin
     
    John J. Trammell, Jun 21, 2004
    #4
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. aa
    Replies:
    6
    Views:
    612
    Jeff @ Dart
    Mar 8, 2005
  2. James
    Replies:
    2
    Views:
    14,120
    Andrew Thompson
    Dec 7, 2004
  3. Benjamin Han
    Replies:
    7
    Views:
    625
    Hartmut Goebel
    Jan 3, 2004
  4. hg

    get script path

    hg, Dec 4, 2006, in forum: Python
    Replies:
    3
    Views:
    565
    Rob Wolfe
    Dec 4, 2006
  5. marss
    Replies:
    5
    Views:
    1,210
    marss
    Sep 13, 2007
  6. Moistly
    Replies:
    0
    Views:
    589
    Moistly
    Nov 22, 2007
  7. dude
    Replies:
    5
    Views:
    2,047
    Jussi Piitulainen
    Mar 17, 2011
  8. Antoon Pardon
    Replies:
    5
    Views:
    256
    Andrew Cooper
    Apr 23, 2014
Loading...