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. Advertising

  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. Advertising

  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. Advertising

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:
    392
    Jeff @ Dart
    Mar 8, 2005
  2. Moistly
    Replies:
    0
    Views:
    375
    Moistly
    Nov 22, 2007
  3. Antoon Pardon
    Replies:
    5
    Views:
    69
    Andrew Cooper
    Apr 23, 2014
  4. Tim Golden
    Replies:
    0
    Views:
    42
    Tim Golden
    Apr 22, 2014
  5. Frank Millman
    Replies:
    0
    Views:
    48
    Frank Millman
    Apr 22, 2014
Loading...

Share This Page