permanentE has asked for the wisdom of the Perl Monks concerning the following question:

Long story, but I need to replace a perl that came with an application with my own compiled perl. It needs to be a drop-in binary compatible version, there are a lot of modules and database drivers that need to work. After I figured out how to make @INC to be the same, I can't figure out what is going on with %ENV. I thought that %ENV came from the shell's environment. But apparently not:
[root@jove tmp]# ./newperl -e 'print join " ", keys %ENV;print "\n"'; HOSTTYPE LOGNAME MAIL OSTYPE HOME MANPATH SHLVL OLDPWD PWD PATH SSH_TT +Y TZ PS1 SHELL TERM MACHTYPE ORACLE_HOME _ USER HOSTNAME [root@jove tmp]# ./oldperl -e 'print join " ", keys %ENV;print "\n"'; PX_ANI_PORT CLASSPATH SATMP PX_USER VERSION SVC_ENTRY_DMGT PX_LOGFILE +HOME JAVA_HOME I_MODE PX_OSA_PORT PX_DATASTORE PX_SCLASSDIR PX_GROUP +PX_JRN_PORT OSAGENT_PORT PRODVERS PX_PROTOCOL DMGT_START BASEDIR ASAN +Y PX_BINDIR LANG UPDATE LC_ALL EMAIL PX_WEB_PORT PX_HLPDIR PX_CONFDIR + TZ I_CONF_SYSLOG VENDOR PX_DOCURL CWMIBDIR PX_DMGTHOST NMSROOT PSTAM +P PX_TMPDIR TERM OAMBASE SQLANY PX_DOCDIR PATCHVER SVC_ENTRY_OSA DESC + PKGINST PX_DATADIR NAME PKG ASTMP PX_APPDIR PX_LOGDIR ALIAS PX_PORT +PKGSAV PX_CGIURL PKGOWNER CLASSES SVC_ENTRY_SSL LD_LIBRARY_PATH PX_CL +ASSURLPX_CTRBDIR PRODNAME PX_DMGT_PORT PX_CGIDIR NLSPATH INSTDATE BUI +LD_ID PX_CLASSDIR PX_LIBDIR ARCH CATEGORY PX_HOST SVC_ENTRY_JRN PATH +DMGT_PORT HOTLINE SVC_ENTRY_WEB PX_FACILITY [root@jove tmp]#
Where are all those extra environment variables coming from in oldperl?

Replies are listed 'Best First'.
Re: Where does %ENV come from?
by Elian (Parson) on Jul 30, 2003 at 00:00 UTC
    %ENV does come from the environment. But that doesn't mean that the environment you see from the shell is the same environment as perl sees. While not common, C libraries can add things to the environment as they initialize, as can perl extensions and if your old perl is statically linked to things (I'd suspect at least Java in some form or fashion from the output) then that may well be where they're coming from. Check your old perl to see what extensions are in statically.
      Thanks, but this brings up a lot more questions: How can I check my old perl for static extensions? How do you compile static extensions into perl? In general how could you compile environment variables into perl. ps. It's not a wrapper
        To see what has been built in statically, take a look at Config's static_ext setting. This command line'll do that:
        perl -MConfig -e 'print $Config{static_ext}'
        It'll be empty, or perhaps have a dl* entry of some sort in it. If there's anything else, well, you have static extensions built in.

        You don't compile environment variables into perl, rather you compile in modules that, at initialization time, set keys in %ENV. If you built in Foo, say, the Foo boot code, which is executed when the module is initialized (which for statically built modules is when perl is started), can put things in %ENV.

Re: Where does %ENV come from?
by sauoq (Abbot) on Jul 29, 2003 at 23:48 UTC
    I thought that %ENV came from the shell's environment.

    Usually, it does. But all bets are off when you are using a binary that was distributed specifically for use with a particular application.

    -sauoq
    "My two cents aren't worth a dime.";
    
Re: Where does %ENV come from?
by Abigail-II (Bishop) on Jul 30, 2003 at 08:36 UTC
    Agreeing with all that Elian has said, there's another common technique to set up one or more environment variables "automatically", and that's the use of a wrapper.

    Check to see if oldperl isn't a wrapper program (either a shell script or a binary) that sets up some environment variables, and then calls the real perl binary.

    Abigail