in reply to Get My Own Name

Yep. At first blush if you use $0 that will give you the name of the script being executed. But be careful. Let me show you a few case studies.

Invoking a script via the interpreter

Consider the following very simple script:
#!/usr/bin/perl -w print $0,"\n";
If I invoke it as
perl testzero.pl
sure enough it prints testzero.pl to stdout. Let's add a wrinkle! If I execute it as perl /home/peter/testzero.pl then then entire path name will be printed to stdout.

chmod'ed script

If I do a chmod 755 testzero.pl on my hapless script (assuming *nix environment here) then I have a similar problem. Executing
./testzero.pl
will yield ./testzero.pl to stdout and so forth.

In summary, hes you can get the path name of the script being executed but make sure you understand all of the implications.


Peter L. Berghold -- Unix Professional
Peter at Berghold dot Net
   Dog trainer, dog agility exhibitor, brewer of fine Belgian style ales. Happiness is a warm, tired, contented dog curled up at your side and a good Belgian ale in your chalice.

Replies are listed 'Best First'.
Re: Re: Get My Own Name
by EvdB (Deacon) on Feb 04, 2004 at 16:42 UTC
    There is also the interesting ( althought not relevant to the OP ) case of doing:
    perl -e 'print "My name is $0.\n\n";'

    which produces: "My name is -e."

    --tidiness is the memory loss of environmental mnemonics

Re: Re: Get My Own Name
by halley (Prior) on Feb 05, 2004 at 14:49 UTC

    If you need to figure out the current script, with path or not, FindBin.

    use FindBin; print $FindBin::Bin, $/;

    --
    [ e d @ h a l l e y . c c ]