How to locate my script file itself when it is called by others.

Discussion in 'Perl Misc' started by MorningStar, Aug 2, 2005.

  1. MorningStar

    MorningStar Guest

    I wrote a perl script and it will be called by other modules.
    Now I need to know where I(my script) am when I am called.
    For example: If my script located in:
    /home/morningstar/a.pl
    And some one called it from:
    [home/someone]$ /home/morningstar/a.pl
    or even
    [home/someone]$ a.pl (if /home/morningstar is in $PATH ENV)

    Then when a.pl was executed, how can it get its location:
    "/home/morningstar/"?

    If you don't understand what do I mean, just imagin the functionality
    of 2 Windows API: GetModuleFileName and GetModuleFileNameEx.

    Thanks.
     
    MorningStar, Aug 2, 2005
    #1
    1. Advertising

  2. MorningStar wrote:
    > I wrote a perl script and it will be called by other modules.
    > Now I need to know where I(my script) am when I am called.
    > For example: If my script located in:
    > /home/morningstar/a.pl
    > And some one called it from:
    > [home/someone]$ /home/morningstar/a.pl
    > or even
    > [home/someone]$ a.pl (if /home/morningstar is in $PATH ENV)
    >
    > Then when a.pl was executed, how can it get its location:
    > "/home/morningstar/"?


    perldoc FindBin


    John
    --
    use Perl;
    program
    fulfillment
     
    John W. Krahn, Aug 2, 2005
    #2
    1. Advertising

  3. MorningStar

    MorningStar Guest

    3x
     
    MorningStar, Aug 2, 2005
    #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. Apricot
    Replies:
    4
    Views:
    560
    velthuijsen
    Apr 16, 2004
  2. sj
    Replies:
    6
    Views:
    388
  3. Steven G. Harms
    Replies:
    7
    Views:
    193
    Robert Klemme
    Feb 17, 2008
  4. zaphod
    Replies:
    7
    Views:
    189
    Tad McClellan
    Jun 21, 2005
  5. Travis
    Replies:
    3
    Views:
    409
Loading...

Share This Page