Subject: | Fatal Error if $_ is set to a Readonly value when IPC::run() is called |
Script dies with error
Modification of a read-only value attempted at <...>/IPC/Run.pm
line 1695
if $_ is set to a Readonly value when IPC::run() is called.
Example:
Readonly::Array my @UPPERCASE => 'A' .. 'C';
run_echo( $_ ) for @UPPERCASE;
where sub run_echo() calls IPC::run()
Interestingly, in sub run_echo(), $_[0] (which is an alias for the
global $_) does not have to be passed to IPC::run() to trigger the
error. Just its existence is enough. The culprit seems to be
IPC/Run.pm, line 1695:
local $_ ;
IPC-Run-0.79
Readonly-1.03
Test-Simple-0.62
This is perl, v5.8.4 built for i686-linux-thread-multi
Linux coitlx05 2.4.21-32.0.1.ELhugemem #1 SMP Tue May 17 17:43:22 EDT
2005 i686
Subject: | ipcrun.t |
#!/ms/dist/perl5/bin/perl5.8
#
# Test script to reproduce error:
# Modification of a read-only value attempted at //ms/dist/perl5/PROJ/IPC-Run/0.79/lib/perl5/IPC/Run.pm line 1695
#
# Global $_ is set to a Readonly value when IPC::run() is called.
# Note that in test below, $value (which is $_) is not actually passed to IPC::run()
#
use strict;
use warnings;
use IPC::Run 'run';
use Test::More qw( no_plan );
use Readonly;
my @lowercase = 'a' .. 'c';
Readonly::Array my @UPPERCASE => 'A' .. 'C';
Readonly my @MIXEDCASE => qw( X y Z );
run_echo( $_ ) for ( @lowercase, @UPPERCASE, @MIXEDCASE );
sub run_echo {
my $value = shift;
# my @args = ( '/bin/echo', $value );
my @args = ( '/bin/echo', 'hello' );
my $t = "test case '$value': '@args'";
diag( "Running $t" );
my( $in, $out, $err );
my $rv = run( [ @args ], \$in, \$out, \$err )
or die "Cannot run @args: $err";
ok( $rv, "Ran $t: OK" );
diag( $out );
}