pulling or getting perl script name inside script

J

J M

I have writeLog sub across several perl scripts that I use to generate logs
from scripts. I like to put script name in side log. Until now I have been
manually putting script name in writeLog sub but is there a way to pull
script name dynamically so I don't have to use static script names inside
perl script? TIA!
 
A

A. Sinan Unur

I have writeLog sub across several perl scripts that I use to generate
logs from scripts. I like to put script name in side log. Until now I
have been manually putting script name in writeLog sub but is there a
way to pull script name dynamically so I don't have to use static
script names inside perl script? TIA!

D:\Home> cat I_ought_to_read_the_docs_before_posting
print "$0\n";

D:\Home> perl I_ought_to_read_the_docs_before_posting
I_ought_to_read_the_docs_before_posting

Specifically, perldoc perlvar

Sinan
 
T

Tad McClellan

J M said:
is there a way to pull
script name dynamically


No need to "pull" it from anywhere, it is already sitting there
in a scalar variable, waiting for you to use it.

A friendly Perl program:

print 'Hi ', scalar(getpwuid($>)), ". My name is $0. How are you today?\n";
# ^^
# ^^ program name
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top