58 users online (1 members and 57 guests)  

Thread: using $0


  Results 1 to 5 of 5
  1. #1
    moshleib's Avatar
    New User

    Status
    Offline
    Join Date
    Apr 2005
    Posts
    5

    using $0

    Hi all. I'm trying to receive the current running script's name. $0 gives me the script that called the current one (the parent ...).
    any ideas ???

    Tnx a lot.

  2. #2
    ALL's Avatar
    Super Dooper Nerd

    Status
    Offline
    Join Date
    Feb 2005
    Location
    localhost
    Posts
    382

    Re: using $0

    sorry, i have been tied up with our biker rally, and have been unable to keep up on this section, here is what you are looking for:
    Code:
    print $ENV{'REQUEST_URI'};

  3. #3
    moshleib's Avatar
    New User

    Status
    Offline
    Join Date
    Apr 2005
    Posts
    5

    Re: using $0

    Hi there.
    Thanks for your answer. I think that $ENV{'REQUEST_URI'} and $0 does exactly the same. They both gave me the parent's address and not the current one.

    Thanks, anyway.

  4. #4
    ALL's Avatar
    Super Dooper Nerd

    Status
    Offline
    Join Date
    Feb 2005
    Location
    localhost
    Posts
    382

    Re: using $0

    oah, so you are trying to recieve what the scripts name is that is ran using the "require" method...

    in that case... well... i dont think you can call its name without having the parent script return it to the script.

  5. #5
    fireartist's Avatar
    New User

    Status
    Offline
    Join Date
    Sep 2005
    Posts
    3

    Re: using $0

    If your script is being called by the 'require' function, then you can get the filename by doing the following.
    Take note however, that different versions of perl may differ in their error reporting, and this could break.

    Also, if you're needing to do this, it suggests a design problem in the program, how about posting more code which shows why you're needing to do this, and we could see if there's a better solution?

    Code:
    use strict;
    use warnings;
    
    eval {die};
    print $@ =~ /(\w+\.pl)/;
    $@ contains the error message from the 'die'.
    The regular expression extracts a string of word characters ending in a dot, then pl

    If you don't know in advance that the filename will end with a particular file extension, then you'll have to approach the regular expression differently. Print out $@ to see the complete error message.



Tags for this Thread