develooper Front page | perl.perl5.porters | Postings from February 2000

Env::Array POD

Thread Next
Gregor N. Purdy
February 7, 2000 13:09
Env::Array POD
Message ID:

As my earlier message indicated, I've written an Env::Array
module that I'd like to see make it into the main distro. I
think it makes a good companion to the existing Env module.

I present for discussion the POD from the latest development

The module uses tied arrays, and implements the following



=head1 NAME

Env::Array - Perl module that "imports" environment variables as arrays


With explicit delimiters:

     use Env::Array qw(PATH :);
     use Env::Array qw(@MANPATH :);

With inferred delimiters:

     use Env::Array qw(@LD_LIBRARY_PATH);


The C<Env::Array> Perl module allows environment variables to be treated
as Perl array variables, analogous to the way the C<Env> module allows
them to be treated as scalar variables.

The Env::Array::import() function requires pairs of environment variable
names and delimiter strings to be presented in the C<use> statement. If
just one argument is given, then C<$Config::Config{path_sep}> is taken
as the delimiter. C<Env::Array> allows the variable name to have the
'C<@>' array type prefix, if desired. The variable being tied must
otherwise begin with a letter. Unlike C<Env>, C<Env::Array> does nothing
if the C<use> list is empty.

After an environment variable is tied, just use it like an ordinary array.
Bear in mind, however, that each access to the variable requires splitting
the string anew.

The code:

     use Env::Array qw(@PATH);
     push @PATH, '.';

is equivalent to:

     use Env qw(PATH);
         $PATH .= ":.";

except that the C<Env::Array> approach does the right thing for both
Unix-like operating systems and for Win32. Also, if C<$ENV{PATH}> was
the empty string, the C<Env> approach leaves it with the (odd) value
"C<:.>", but the C<Env::Array> approach leaves it with "C<.>".

C<Env::Array> requires Perl 5.005 or later for proper operation due to its
use of tied arrays.

=head1 SEE ALSO

The C<Env> Perl module.

=head1 AUTHOR

Gregor N. Purdy E<lt>F<>E<gt>


Copyright (C) 1999-2000 Gregor N. Purdy. All rights reserved.
This program is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.


| Gregor N. Purdy            |
|                                                              |
| Swiss army chainsaw operator.      y2k: perl -pe 'tr/yY/kK/' |

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About