2003-03-16

use Env qw(VAR) and foreach $VAR (…) don’t like each other

Submitted Perl 5 bug #21594.

[tryme demonstration script originally written 2000-09-07]

This script doesn't DWIM. The $BAR stuff works fine. But, the $FOO stuff inside the foreach doesn't. In that case, the changes to the environment variable FOO are not visible to the shell.

 ____________________________ tryme ____________________________
/                                                               \
#!/usr/bin/perl -w

#
# Use an evar:
#

use Env qw(BAR);

$BAR = 'howdy';
print       "[perl ] BAR = \"$BAR\"\n";
system 'echo [shell] BAR = \"$BAR\"';

print "\n";

#
# Now, use one in a foreach:
#

use Env qw(FOO);
my @a = qw(foo bar splee);

foreach $FOO (@a) {
    print       "[perl ] FOO = \"$FOO\"\n";
    system 'echo [shell] FOO = \"$FOO\"';
}
\_______________________________________________________________/

No comments: