Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Perl Executable and Script Name -- NOT Args

Reply
Thread Tools

Perl Executable and Script Name -- NOT Args

 
 
Kevin Mooney
Guest
Posts: n/a
 
      11-29-2004
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, http://www.velocityreviews.com/forums/(E-Mail Removed)


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.
 
Reply With Quote
 
 
 
 
Walt Stoneburner
Guest
Posts: n/a
 
      11-29-2004
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, (E-Mail Removed)
 
Reply With Quote
 
 
 
 
Paul Lalli
Guest
Posts: n/a
 
      11-29-2004
"Walt Stoneburner" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> 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

 
Reply With Quote
 
Christopher Nehren
Guest
Posts: n/a
 
      11-29-2004
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.
 
Reply With Quote
 
Paul Lalli
Guest
Posts: n/a
 
      11-29-2004
"Christopher Nehren" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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

 
Reply With Quote
 
Ben Morrow
Guest
Posts: n/a
 
      11-30-2004

Quoth "Paul Lalli" <(E-Mail Removed)>:
> "Walt Stoneburner" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) om...
>
> 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.'
(E-Mail Removed)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
forwarding Args&&... vs forwarding Args... Andrew Tomazos C++ 5 01-05-2012 11:15 PM
C++0x -- fun(Args&...) and fun(Args const&...) er C++ 2 12-20-2010 07:52 PM
Is there a class or method to construct url args or extract url args? Ken Varn ASP .Net 2 06-22-2005 12:26 PM
args v. *args passed to: os.path.join() Pierre Fortin Python 2 09-18-2004 06:59 PM
When passing functions as args,how to pass extra args for passed function? python@sarcastic-horse.com Python 3 09-17-2003 12:25 AM



Advertisments