And the clouds parted, and [EMAIL PROTECTED] said...
> Hi,
> 
> I have a little problem. I have script "test.pl" and inside this script I want to 
> know what is "my name" (I mean this "test.pl".
> 
> test.pl script
> ---------------
> 
> my $this_scripts_name_is = who_am_I();
> 
> sub who_am_I
> {
>   my $my_name = xxxx; # what I have to put to this "xxxx" to get "test.pl" scripts 
> name
> 
>   return $my_name;
> }
> 

I ran into exactly this issue, but I wanted to just get the actual script
name.  $0 returns the entire path the script was invoked as.  ie - $0 could
be "../../foo/bar/blarch/scriptname.pl", but I just wanted "scriptname.pl".

Here's a line that will give you exactly that.
($PROGNAME = $0) =~ s|(\.?\.?(/[^/]+)*/)?([^/]+)|$3|;

...or, to put it in the above terms:

my $this_scripts_name_is = who_am_I();

sub who_am_I
{
        my $PROGNAME;
        ($PROGNAME = $0) =~ s|(\.?\.?(/[^/]+)*/)?([^/]+)|$3|;

        return $PROGNAME;
}

HTH-
Brian

  /~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\
 | Brian Gerard                          Overflow on /dev/null;           |
 | First initial + 'lists'            please empty the bit bucket.        |
 | at technobrat dot com                                                  |
  \______________________________________________________________________/

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to