... but it's going here because I'm definitely going to need to forget it.
In a Perl script, the array @ARGV contains the command-line arguments, but not the filename of the script itself; that's stored in $0. Not the same as in C, where argv[0] is the path to the program under execution. (Thanks to !AWARE for this).
With any luck, this will give you the path to the script (followed by a '/' if required) or just "" if the script is in the current directory:
# Get the path to the current script sub getPath { my $scriptPath = $0; if ( $scriptPath =~ m|^(.*/)| ) { return $1; } else { return ""; } }
2:42:26 PM
|