"In C / C++ (bash, too?) the first command-line argument, argv[0], is the binary filename"
is dead wrong, by the way. The ISO standard mandates no such thing.
From C99:
If the value of argc is greater than zero, the string pointed to by argv[0] represents the program name; argv[0][0] shall be the null character if the program name is not available from the host environment.
And notice that it states "represents the program name", not "is the location of the binary executable". That's because there's an earlier snippet which states:
... the array members argv[0] through argv[argc-1] inclusive shall contain pointers to strings, which are given implementation-defined values by the host environment prior to program startup."
It's quite legal for your argv[0]
for the command "sleep 60" to be "pax's fantastic sleep utility" rather than "/bin/sleep".
In short, the environment doesn't have to provide a representation of the program and, even if it does, it doesn't have to be anything usable for locating the binary.
But, having bored you with my diatribe, Perl provides $0
or $PROGRAM_NAME
(in that hideous "English" mode) for this purpose. See perlvar for details.