Env::ShellWords(3pm)

Env::ShellWords3pm

Environment variables for arguments as array

Usage

 # Tie Interface
 use Env::ShellWords;
 tie my @CFLAGS,  'Env::ShellWords', 'CFLAGS';
 tie my @LDFLAGS, 'Env::ShellWords', 'LDFLAGS';
 # same thing with import interface:
 use Env::ShellWords qw( @CFLAGS @LDFLAGS );
 # usage:
 $ENV{CFLAGS} = '-DBAR=1';
 unshift @CFLAGS, '-I/foo/include';
 push @CFLAGS, '-DFOO=Define With Spaces';
 
 # now:
 # $ENV{CFLAGS} = '-I/foo/include -DBAR=1 -DFOO=Define\\ With\\ Spaces';
 
 unshift @LDFLAGS, '-L/foo/lib';
 push @LDFLAGS, '-lfoo';

Version

version 0.02

Overview

This module provides an array like interface to environment variables that contain flags. For example Autoconf can uses the environment variables like "CFLAGS" or "LDFLAGS", and this allows you to manipulate those variables without doing space quoting and other messy mucky stuff.

The intent is to use this from alienfile to deal with hierarchical prerequisites.

You can provide split and join callbacks when you tie:

 use Env::ShellWords;
 # split on any space, ignore quotes
 tie my @FOO, 'Env::ShellWords',
   sub { split /\s+/, $_[0] },
   sub { join ' ', @_ };

Which may be useful if you have to split on words on an operating system with a different specification.

Caveats

Not especially fast. "undef" gets mapped to the empty string '' since "undef" doesn't have a meaning as an argument in a string.

Writing to an environment variable using this interface is inherently lossy.

Author

Graham Ollis <[email protected]>

From perl-env-shellwords 0.02-11 in Arch Linux 2026-11-01. Parsed by carta from the page's man source.