I don't see your pure-Perl "Modification of a read-only value..." result on ActiveState 5.8.9 and Strawberry 5.14.4.1 (Update: likewise Strawberries 5.10.1.5 and 5.12.3.0), but there's something else I don't understand:
c:\@Work\Perl\monks>perl -wMstrict -MData::Dumper -le
"sub modify { $_ = 5 for @_; }
;;
my @a;
@a = (undef) x 5;
;;
modify(@a);
print Dumper \@a;
;;
my @b;
$#b = 4;
;;
modify(@b);
print Dumper \@b;
;;
my @c;
$#c = 4;
$c[ $#c ] = undef;
;;
modify(@c);
print Dumper \@c;
"
$VAR1 = [
5,
5,
5,
5,
5
];
$VAR1 = [
undef,
undef,
undef,
undef,
undef
];
$VAR1 = [
undef,
undef,
undef,
undef,
5
];
Arrays
@b and
@c are still unwriteable (or at least unwritten, at least in part), but in a different way.
?!?
Update: Taking the @_ argument list out of the equation, I get expected results (thank Larry!) for the problematic cases above (for all Perl versions listed in the first paragraph):
c:\@Work\Perl\monks>perl -wMstrict -MData::Dumper -le
"my @b;
$#b = 4;
;;
$_ = 5 for @b;
print Dumper \@b;
;;
my @c;
$#c = 4;
$c[ $#c ] = undef;
;;
$_ = 6 for @c;
print Dumper \@c;
"
$VAR1 = [
5,
5,
5,
5,
5
];
$VAR1 = [
6,
6,
6,
6,
6
];
Give a man a fish: <%-{-{-{-<
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.