Variables de entorno

El hash %ENV contiene las variables de entorno. Su modificación implica la modificación del entorno del programa.
$ENV{PATH} = $ENV{PATH}:"/home/casiano/bin";
delete $ENV{DISPLAY};
system 'myls';
En este ejemplo el program myls es ejecutado en un entorno en el cual el PATH incluye a /home/casiano/bin y la variable DISPLAY ha sido suprimida.

Ejercicio 1.3.1   En Perlmonks apareció la siguiente pregunta (puede encontrarla buscando en http://www.perlmonks.org/ por 'Environmental Settings'.
I require some assistance. I am writing a CGI script in Perl on Solaris
that needs to run external commands using the 'system' operator. These
commands are part of a larger package that needs the system initialized
(via a command) properly before execution, or else each individual
command cannot interact with the other, like the following.

1: system "/PATH/initialize_system"; # init the environment
2: system "/PATH/skew.k ARG_FOR_FRAME_NUMBER"; # create image
3: system "/PATH/savegif.k FRAME_NUMBER"; # save image off
4: system "exit"; # exit the environment created with initialize_system

When running a command using 'system', the environment appears to only
lasts until the next line of Perl code, so line 2 can't talk to line
3 because the environment required for them to communicate isn't there
which is initialized by line 1. The above code snippet would the way it
is run from a command line. 

Any help would be appreciated. 
Thanks.

¿Cuál es su respuesta?

Ejercicio 1.3.2   Ejecute los comandos:
$ set | grep "^[A-Z]" |wc
$ perl -e 'print "$_ = $ENV{$_}\n" for sort keys %ENV;' | wc
¿A que se debe la diferencia?. Observe el siguiente experimento:
$ FOO='Hello, World!'
$  perl -le'print $ENV{FOO}'
$
$ export FOO='Hello, World!'
$  perl -le'print $ENV{FOO}'
Hello, World!

Casiano Rodríguez León
Licencia de Creative Commons
Programación Distribuida y Mejora del Rendimiento
por Casiano Rodríguez León is licensed under a Creative Commons Reconocimiento 3.0 Unported License.

Permissions beyond the scope of this license may be available at http://campusvirtual.ull.es/ocw/course/view.php?id=44.
2012-06-19