pulling or getting perl script name inside script

Discussion in 'Perl Misc' started by J M, Nov 6, 2004.

  1. J M

    J M Guest

    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!
    J M, Nov 6, 2004
    #1
    1. Advertising

  2. "J M" <> wrote in
    news:h2Xid.22397$:

    > 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
    A. Sinan Unur, Nov 6, 2004
    #2
    1. Advertising

  3. J M <> wrote:

    > 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


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
    Tad McClellan, Nov 6, 2004
    #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,756
  2. =?iso-8859-1?B?bW9vcJk=?=
    Replies:
    7
    Views:
    795
    Roedy Green
    Jan 2, 2006
  3. ding feng
    Replies:
    2
    Views:
    2,771
    ding feng
    Jun 25, 2003
  4. Bobby Chamness
    Replies:
    2
    Views:
    2,371
    Joe Smith
    Apr 22, 2007
  5. Replies:
    20
    Views:
    652
    Gunnar Hjalmarsson
    Jan 18, 2005
Loading...

Share This Page