in reply to Cava Packager quick question

I have noticed the same thing, as I tried to use it for the USAGE: response on invalid parameters. I didn't find a solution at the time, but it wasn't important to my script.

Just in case this is an XY problem, what exactly do you want to use $0 for? There are always other ways to do things.

Replies are listed 'Best First'.
Re^2: Cava Packager quick question
by rmflow (Beadle) on Mar 25, 2010 at 14:38 UTC
    $0 is used for Windows Registry entries to invoke my application from other applications. $0 variable allowed me to use my application without knowing what I'm actually running (.exe or .pl)

      Could you not set a registry entry with "perl script.pl" vs "script.exe" when you install your script? Another thing you might do is set the associations so that .pl files are opened with the perl interpreter (just say "script" and away you go). You could also place a batch file in the directory to launch whatever style you've installed (run startscript.bat).

      I'm not really sure how $0 helps you there however... you'd have to run your application to populate $0 in the first place, and at that point you're already running the code so you must have found it. Chicken vs Egg.

        in my script I have '--install' option and the code determines if we are .exe or .pl and then writes to Registry '$0' or 'wperl $0'

        Of course it is not a problem, but now it is less flexible because I had to define the application's name in configuration file.