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

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

  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. 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. dpackwood
    Replies:
    3
    Views:
    1,830
  2. Jonas
    Replies:
    4
    Views:
    964
  3. Replies:
    4
    Views:
    261
  4. volcano
    Replies:
    4
    Views:
    1,798
    volcano
    Sep 24, 2009
  5. cassiope
    Replies:
    16
    Views:
    970
    cassiope
    Jan 6, 2010
Loading...

Share This Page