perlenv

Package: WA2L/edrc 1.5.57
Section: Library Commands (3)
Updated: 07 June 2021
Index Return to Main Contents

 

NAME

perlenv - print environment needed to start perl scripts

 

SYNOPSIS

edrc/lib/perlenv [ -n ]

 

AVAILABILITY

WA2L/edrc

 

DESCRIPTION

print the environment used by perl to access the Perl modules bundled with WA2L/edrc.

To set the environment prior to the execution of perl, invoke:

  eval `perlenv` 

This command is *only* to be used to prepare the environment to execute Perl scripts in "Recovery Script" trees. See perl_modules(3) for information regarding this usage.

When writing Perl scripts for WA2L/edrc, do *not* use perlenv, start the script thru the .perl_wrapper. See perl_wrapper(1) for information about integrating a Perl script into WA2L/edrc.

 

OPTIONS

-n
no export VARIABLE ... output.

 

ENVIRONMENT

$PERLLIB
this variable holds Perl module locations additional to the standard applying to an installation. This variable will be expanded with the bundled Perl module locations when executing the perlenv command.

$LD_LIBRARY_PATH
path of additional shared libraries loaded by the ld dynamic linker. This variable will be expanded with the shared library locations for a certain Os-Id distributed with WA2L/edrc when executing the perlenv command.

$SHLIB_PATH
this variable is expanded as the $LD_LIBRARY_PATH is done. This variable has basically the same function as the $LD_LIBRARY_PATH and is mostly active on HPUX systems.

$PATH
command search path. This variable will be expanded with the path where the perl interpreter was found on the system when executing the perlenv command. See also perl_wrapper(1) for more information.

 

EXIT STATUS

0
always

 

FILES

edrc/lib/perl_wrapper.cfg
configuration file for .perl_wrapper and perlenv.

edrc/lib/perl/pm/
location of all bundled perl modules. The related directories in edrc/lib/perl/pm/ are pre-pended to the $PERLLIB environment variable when executing perlenv. The pmdesc -h command can also be used to display the current Perl library path.

The directory structure in edrc/lib/perl/pm/ is:

Legacy Structure:

perl<rel>/<vers>/
perl<rel>/site_perl/<vers>/
perl<rel>/vendor_perl/<vers>/
perl<rel>/edrc_perl/
perl<rel>/share/<vers>/bin/
perl<rel>/share/<vers>/man/
perl<rel>/share/site_perl/<vers>/bin/
perl<rel>/share/site_perl/<vers>/man/
perl<rel>/share/vendor_perl/<vers>/bin/
perl<rel>/share/vendor_perl/<vers>/man/

New Structure:

perl<rel>/<vers>/root/
perl<rel>/edrc_perl/

Where <rel> is the major version number (e.g. 5) and <vers> is the whole perl version (e.g. 5.14.3).

The "Legacy Structure" and the "New Structure" can be and is mixed. However, the "Legacy Structure" will not disappear and all files will remain as they are; new modules will be installed into the more simple "New Structure". When using the .perl_wrapper to start a perl script and the perlenv commands to initialize the perl environment, scripts need no change.

See also: perl_modules(3), pmdesc(1).

edrc/src/perlmodules/
source packages of all bundled perl modules to enable a fast compilation exercise when having a different perl version on the system. See README file and use the provided Makefile(s) to build and install the related module.

edrc/lib/<Os-Id>/libs/
location of operating system dependent shared libraries outside of Perl. This directory is appended to the $LD_LIBRARY_PATH and the $SHLIB_PATH environment variables when executing perlenv.

 

EXAMPLES

1) Start a Perl script from a recovery script

To start a Perl script that uses a bundled Perl module from a recovery script, set the Perl library path (@INC) using the 'eval `perlenv`' command in the recovery script and then call the perl interpreter.

Recovery script:

  #!/bin/ksh
  #
  # 1:ascript - A Recovery Script  
  #
  # [00] 08.02.2009 CWa Initial Version
  #
  #
  test "$DEBUG" = True && set -x
  :
  :
  eval `perlenv`
  perl ./perlscript
  :

Perl script:

  #
  # perlscript - Perl script using bundled DBI module
  #
  # [00] 18.03.2009 CWa Initial Version
  #
  :
  :
  use DBI;
  :

2) Start a Perl script from a recovery script using the _env file mechanism

Create an _env file (using the env edrc command) and start the Perl script from the recovery script.

_env file:

  #
  # _env - Environment settings for commands in /apps/eg
  #
  # [00] 18.03.2009 CWa Initial Version
  #
  #
  test "$DEBUG" = True && set -x
  
  eval `perlenv`
  :

Recovery script:

  #!/bin/ksh
  #
  # 1:ascript - A Recovery Script  
  #
  # [00] 08.02.2009 CWa Initial Version
  #
  #
  test "$DEBUG" = True && set -x
  :
  :
  perl ./perlscript
  :

Perl script:

  #
  # perlscript - Perl script using bundled DBI module
  #
  # [00] 18.03.2009 CWa Initial Version
  #
  :
  :
  use DBI;
  :

3) Write a recovery script in Perl

Create an _env file (using the env edrc command) and write the recovery script in Perl.

_env file:

  #
  # _env - Environment settings for commands in /apps/eg
  #
  # [00] 18.03.2009 CWa Initial Version
  #
  #
  test "$DEBUG" = True && set -x
  
  eval `perlenv`
  :

Perl recovery script:

  #!/usr/bin/env perl
  #
  # 1:ascript - A Recovery Script  
  #
  # [00] 08.02.2009 CWa Initial Version
  #
  :
  :
  use DBI;
  :

Note the use of '#!/usr/bin/env perl' in the magic key to start the Perl script. This ensures that the perl interpreter is found on the system, even when it is not installed in the default location you will normally specify. The path to the perl interpreter is added to the $PATH using the perlenv command.

4) Write a perl script outside of WA2L/edrc and profit from bundled perl modules

The startup method method (see also: https://perldoc.perl.org/perlrun) below allows to start the perl interpreter from wherever it is installed and also enables to use all perl modules bundled with WA2L/edrc using the perlenv command to dynamically initialize the environment.

This method is similar to the use of the .perl_wrapper, but the perl script can be placed somewhere of your liking outside of WA2L/edrc.

Set the permissions of the script to executable:

  chmod +x perlscript

Perl script:

  #!/bin/ksh
  #
  # perlscript - Perl script using bundled modules
  #
  # [00] 18.03.2009 CWa Initial Version
  #
  eval `~edrc/lib/perlenv`
  #! -*- perl -*- -p
  eval 'exec perl -x -SS $0 ${1+"$@"}'
      if 0;
  
  use strict;
  use warnings;
  use File::Basename;
  use REST::Client;
  use JSON;
  use DBI;
  use Data::Dumper;
  use Getopt::Std;
  use WA2L::Util;
  :
  :

5) Test the availability of a specific perl module

Set the needed perl environment:

  [ / ] 
  [ root@acme007 ][*edrc*/bash]: eval `perlenv`

Try to access the perl module:

  [ / ] 
  [ root@acme007 ][*edrc*/bash]: perl -e "use REST::Client;"

If an error message like

  Can't locate REST/Client.pm in @INC (you may need to install the REST::Client module)
  (@INC contains: /etc/perl ... /usr/lib/x86_64-linux-gnu/perl-base) at -e line 1.
  BEGIN failed--compilation aborted at -e line 1.

appears, the module cannot be found, if the module can be found there is no output.

 

SEE ALSO

edrcintro(1), cpanm(1), ld(1), osid(3), perl(1), perlversion(3), pmdesc(1), perl_modules(3), perl_wrapper(1), http://search.cpan.org/~mschwern/ExtUtils-MakeMaker/lib/ExtUtils/MakeMaker.pm#make_install, http://search.cpan.org/~jesse/perl/INSTALL#Coexistence_with_earlier_versions_of_perl_5, https://perldoc.perl.org/perlrun

 

NOTES

The following excellent description of the directory structure is a partial extract of http://search.cpan.org/~jesse/perl-5.17.8/INSTALL#Coexistence_with_earlier_versions_of_perl_5 which has been written by Jesse Vincent <esse+cpan@fsck.com>.

Be aware, that the perlenv and .perl_wrapper commands are a bit less strict in the resolution of the directories listed in the $PERLLIB environment variable.

 

Coexistence with earlier versions of perl 5

Perl 5.14 is not binary compatible with earlier versions of Perl. In other words, you will have to recompile your XS modules.

In general, you can usually safely upgrade from one version of Perl (e.g. 5.X.Y) to another similar minor version (e.g. 5.X.(Y+1))) without re-compiling all of your extensions. You can also safely leave the old version around in case the new version causes you problems for some reason.

Usually, most extensions will probably not need to be recompiled to be used with a newer version of Perl. Here is how it is supposed to work. (These examples assume you accept all the Configure defaults.)

Suppose you already have version 5.8.7 installed. The directories searched by 5.8.7 are typically like:

  /usr/local/lib/perl5/5.8.7/$archname
  /usr/local/lib/perl5/5.8.7
  /usr/local/lib/perl5/site_perl/5.8.7/$archname
  /usr/local/lib/perl5/site_perl/5.8.7

Now, suppose you install version 5.8.8. The directories searched by version 5.8.8 will be:

  /usr/local/lib/perl5/5.8.8/$archname
  /usr/local/lib/perl5/5.8.8
  /usr/local/lib/perl5/site_perl/5.8.8/$archname
  /usr/local/lib/perl5/site_perl/5.8.8

  /usr/local/lib/perl5/site_perl/5.8.7/$archname
  /usr/local/lib/perl5/site_perl/5.8.7
  /usr/local/lib/perl5/site_perl/

Notice the last three entries -- Perl understands the default structure of the $sitelib directories and will look back in older, compatible directories. This way, modules installed under 5.8.7 will continue to be usable by 5.8.7 but will also accessible to 5.8.8. Further, suppose that you upgrade a module to one which requires features present only in 5.8.8. That new module will get installed into /usr/local/lib/perl5/site_perl/5.8.8 and will be available to 5.8.8, but will not interfere with the 5.8.7 version.

The last entry, /usr/local/lib/perl5/site_perl/, is there so that 5.6.0 and above will look for 5.004-era pure perl modules.

Lastly, suppose you now install 5.10.0, which is not binary compatible with 5.8.x. The directories searched by 5.10.0 (if you don't change the Configure defaults) will be:

  /usr/local/lib/perl5/5.10.0/$archname
  /usr/local/lib/perl5/5.10.0
  /usr/local/lib/perl5/site_perl/5.10.0/$archname
  /usr/local/lib/perl5/site_perl/5.10.0

  /usr/local/lib/perl5/site_perl/5.8.8

  /usr/local/lib/perl5/site_perl/5.8.7

  /usr/local/lib/perl5/site_perl/

Note that the earlier $archname entries are now gone, but pure perl modules from earlier versions will still be found.

This way, you can choose to share compatible extensions, but also upgrade to a newer version of an extension that may be incompatible with earlier versions, without breaking the earlier versions' installations.

 

BUGS

-

 

AUTHOR

perlenv was developed by Christian Walther. Send suggestions and bug reports to wa2l@users.sourceforge.net . 

 

COPYRIGHT

Copyright © 2021 Christian Walther

This is free software; see edrc/doc/COPYING for copying conditions. There is ABSOLUTELY NO WARRANTY; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


 

Index

NAME
SYNOPSIS
AVAILABILITY
DESCRIPTION
OPTIONS
ENVIRONMENT
EXIT STATUS
FILES
EXAMPLES
SEE ALSO
NOTES
Coexistence with earlier versions of perl 5
BUGS
AUTHOR
COPYRIGHT

This document was created by man2html using the manual pages.
Time: 18:25:06 GMT, May 02, 2025