Perl Executable and Script Name -- NOT Args

Discussion in 'Perl Misc' started by Kevin Mooney, Nov 29, 2004.

  1. Kevin Mooney

    Kevin Mooney Guest

    Walt Stoneburner wrote:
    > I'm stumbling trying to find out if this is even possible with Perl.
    > Anyone know?
    >
    > In a C program, it's possible to get the executable's name as argv[0]
    > -- a trick that's useful when you want one executable and a bunch of
    > symbolic links, but the program's behavior to change based on what it
    > was called. You'll note some crypto packages do this, as it is
    > simplier to have multiple man pages.
    >
    > Since the Perl engine is the executable in reality, I figure the best
    > I'd get is the fully qualified path name of the running executable --
    > which might be useful if I have more than one version of Perl
    > installed.
    >
    > Additionally, if I wanted a program to know about it's own source
    > file, it might be interesting to see what was passed to Perl. This is
    > _different_ than command line arguments being passed to a Perl script.
    > I'd like to know if the Perl engine itself exposes what was passed to
    > it.
    >
    > Anyone know if there are some magic globals or environment variables
    > which contain either of these two pieces of information?
    >
    > -Walt Stoneburner,


    For your first question, I believe $0 is what you are looking for.
    Unfortunately I have no idea as far as your second question goes.
     
    Kevin Mooney, Nov 29, 2004
    #1
    1. Advertising

  2. I'm stumbling trying to find out if this is even possible with Perl.
    Anyone know?

    In a C program, it's possible to get the executable's name as argv[0]
    -- a trick that's useful when you want one executable and a bunch of
    symbolic links, but the program's behavior to change based on what it
    was called. You'll note some crypto packages do this, as it is
    simplier to have multiple man pages.

    Since the Perl engine is the executable in reality, I figure the best
    I'd get is the fully qualified path name of the running executable --
    which might be useful if I have more than one version of Perl
    installed.

    Additionally, if I wanted a program to know about it's own source
    file, it might be interesting to see what was passed to Perl. This is
    _different_ than command line arguments being passed to a Perl script.
    I'd like to know if the Perl engine itself exposes what was passed to
    it.

    Anyone know if there are some magic globals or environment variables
    which contain either of these two pieces of information?

    -Walt Stoneburner,
     
    Walt Stoneburner, Nov 29, 2004
    #2
    1. Advertising

  3. Kevin Mooney

    Paul Lalli Guest

    "Walt Stoneburner" <> wrote in message
    news:...
    > In a C program, it's possible to get the executable's name as argv[0]
    > -- a trick that's useful when you want one executable and a bunch of
    > symbolic links, but the program's behavior to change based on what it
    > was called. You'll note some crypto packages do this, as it is
    > simplier to have multiple man pages.
    >
    > Since the Perl engine is the executable in reality, I figure the best
    > I'd get is the fully qualified path name of the running executable --
    > which might be useful if I have more than one version of Perl
    > installed.


    The currently running executable is stored in $^X. perldoc perlvar
    warns you that depending on your OS, this may be a relative or absolute
    path.

    > Additionally, if I wanted a program to know about it's own source
    > file, it might be interesting to see what was passed to Perl. This is
    > _different_ than command line arguments being passed to a Perl script.
    > I'd like to know if the Perl engine itself exposes what was passed to
    > it.


    The currently executing perl script is stored in $0

    > Anyone know if there are some magic globals or environment variables
    > which contain either of these two pieces of information?


    perldoc perlvar is the place to go to find a list of all global Perl
    variables.

    Paul Lalli
     
    Paul Lalli, Nov 29, 2004
    #3
  4. On 2004-11-29, Paul Lalli scribbled these
    curious markings:
    > perldoc perlvar is the place to go to find a list of all global Perl
    > variables.


    Note that it covers more than just _global_ variables; it also documents
    package variables such as $a and $b, and the dynamically-scoped regular
    expression match variables -- among others.

    --
    I abhor a system designed for the "user", if that word is a coded
    pejorative meaning "stupid and unsophisticated". -- Ken Thompson
    Linux: "How rebellious ... in a conformist sort of way."
    Unix is user friendly. However, it isn't idiot friendly.
     
    Christopher Nehren, Nov 29, 2004
    #4
  5. Kevin Mooney

    Paul Lalli Guest

    "Christopher Nehren" <> wrote in message
    news:...
    > On 2004-11-29, Paul Lalli scribbled these
    > curious markings:
    > > perldoc perlvar is the place to go to find a list of all global

    Perl
    > > variables.

    >
    > Note that it covers more than just _global_ variables; it also

    documents
    > package variables such as $a and $b, and the dynamically-scoped

    regular
    > expression match variables -- among others.


    True. That was a poor choice of words on my part. "built-in Perl
    variables" may be better. Basically, all the variables that exist by
    default without the programmer creating them.

    Paul Lalli
     
    Paul Lalli, Nov 29, 2004
    #5
  6. Kevin Mooney

    Ben Morrow Guest

    Quoth "Paul Lalli" <>:
    > "Walt Stoneburner" <> wrote in message
    > news:...
    >
    > The currently executing perl script is stored in $0


    ....but it may (under some OSen) be just a name, with no path. The
    FindBin module is supposed to solve this problem for you, though I have
    found it a little unreliable in the past; I believe some work has been
    done on it recently, though.

    Ben

    --
    'Deserve [death]? I daresay he did. Many live that deserve death. And some die
    that deserve life. Can you give it to them? Then do not be too eager to deal
    out death in judgement. For even the very wise cannot see all ends.'
     
    Ben Morrow, Nov 30, 2004
    #6
    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. Ken Varn
    Replies:
    2
    Views:
    647
    Ken Varn
    Jun 22, 2005
  2. Replies:
    3
    Views:
    517
    David Eppstein
    Sep 17, 2003
  3. Pierre Fortin

    args v. *args passed to: os.path.join()

    Pierre Fortin, Sep 18, 2004, in forum: Python
    Replies:
    2
    Views:
    721
    Pierre Fortin
    Sep 18, 2004
  4. er
    Replies:
    2
    Views:
    533
  5. Andrew Tomazos
    Replies:
    5
    Views:
    613
Loading...

Share This Page