Get Invoked Script Location in Perl

Discussion in 'Perl Misc' started by fiorentico@gmail.com, Jul 11, 2006.

  1. Guest

    Hi,

    I'd like to obtain the location of the script I am calling. E.g.

    If I am calling

    perl X:\script.pl

    I want to obtain "X:\". How do I do that?

    getcwd and cwd don't apply beacuse I am running the Script from another
    location. Thanks
     
    , Jul 11, 2006
    #1
    1. Advertisements

  2. David Squire Guest

    wrote:
    > Hi,
    >
    > I'd like to obtain the location of the script I am calling. E.g.
    >
    > If I am calling
    >
    > perl X:\script.pl
    >
    > I want to obtain "X:\". How do I do that?
    >
    > getcwd and cwd don't apply beacuse I am running the Script from another
    > location. Thanks
    >


    See perldoc perlvar. Look for the string "Contains the name of the
    program being executed".


    DS
     
    David Squire, Jul 11, 2006
    #2
    1. Advertisements

  3. Ben Morrow Guest

    Quoth "A. Sinan Unur" <>:
    > David Squire <> wrote in
    > news:e90unf$da$:
    >
    > > wrote:
    > >>
    > >> I'd like to obtain the location of the script I am calling. E.g.
    > >>
    > >> If I am calling
    > >>
    > >> perl X:\script.pl
    > >>
    > >> I want to obtain "X:\". How do I do that?

    > >
    > > See perldoc perlvar. Look for the string "Contains the name of the
    > > program being executed".

    >
    > See perldoc FindBin.
    >
    > AFAIK, the contents of $0 are OS dependent.


    They are, and IIRC FindBin doesn't always work on Windows (in
    particular, if the program was found through the PATH then $0 contains
    just the program name, and FindBin fails). They may have fixed it by
    now, of course... :)

    Ben

    --
    If I were a butterfly I'd live for a day, / I would be free, just blowing away.
    This cruel country has driven me down / Teased me and lied, teased me and lied.
    I've only sad stories to tell to this town: / My dreams have withered and died.
    (Kate Rusby)
     
    Ben Morrow, Jul 11, 2006
    #3
    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. Wet Basement
    Replies:
    1
    Views:
    2,817
    BobMonk
    Jul 15, 2003
  2. dpackwood
    Replies:
    3
    Views:
    2,168
  3. Jonas
    Replies:
    4
    Views:
    1,120
  4. Replies:
    4
    Views:
    354
  5. volcano
    Replies:
    4
    Views:
    1,979
    volcano
    Sep 24, 2009
  6. cassiope
    Replies:
    16
    Views:
    1,088
    cassiope
    Jan 6, 2010
  7. Alex Bird
    Replies:
    3
    Views:
    397
    Thomas 'PointedEars' Lahn
    May 9, 2008
  8. Yogi
    Replies:
    1
    Views:
    546
    Peter Makholm
    Sep 13, 2012
Loading...