It is impossible to do the way you are trying to do it.
It either needs a shell script shell that sets LD_LIBRARY_PATH and then calls your perl script, or any user running the script must have LD_LIBRARY_PATH properly configured first.
If you are doing the latter, then this can be controlled globally by editing the shells /etc/profile and /etc/cshrc (for ksh, sh, bash, csh and tcsh). Then you can check the LD_LIBRARY_PATH value in the script, and if you do not install / install it incorrectly, then print a friendly message to the user. Alternatively, individual users can install this in their local .profile / .cshrc files.
Note. You did not provide any information about the environment or users that can run it, so there is also a possibility that users can set LD_LIBRARY_PATH what they need. If you check LD_LIBRARY_PATH for a “good” value in a script, then keep in mind that several paths can be specified, so you will need to parse this environment variable correctly.
source share