Uri wrote: > >>>>> "JP" == John Porter <jdporter@min.net> writes: > > JP> @a = (undef) x 5; # any value; it will get overwritten. > JP> for ( @a ) { > JP> @$_ = (....); > JP> } > > JP> Now, as for the loop problem: why is the semantics of for as > JP> a statement modifier so different from the normal for? > > i still don't get what you expect @$_ to be? explain it in english if > you can. it looks like a symref. if it is meant to be an array ref then > you should initialize @a with ([]) x 5. and i don't think there is any > difference in the semantics of a for loop vs. statement modifier in this > case. you just never had a proper array ref in $_. > > and your comment about any value will be overwritten makes no sense > either. it has to be array refs for @$_ to have any meaning other than > symref. As Rick Delaney said, Autovivification. But I was wrong about it being any value; it has to be undef. If @a contains five undefs, then for any $a[$i], @{ $a[$i] } = () forces $a[$i] to be a new arrayref. If $a[$i] is not undef, then you have other problems. And, AYK, for(@a) causes $_ to be aliased to each of the elements of @a, so you get the same effect. It works. Try it if you don't believe me. @a = (undef) x 5; # any value; it will get overwritten. for ( @a ) { @$_ = ( 'foo', $i++ ); } for ( @a ) { print "(@$_)\n"; } I think it's fun. Although this discussion isn't. Oh. I just discovered something. On perl 5.005_02, on a bsdi system, this all works exactly as I have described (and expected). But perl 5.005_02 (yes, the same version), built with threads, on Solaris 2.6, gives the error Can't use an undefined value as an ARRAY reference Is this another wierd threads bug? John Porter ==== Want to unsubscribe from Fun With Perl? Well, if you insist... ==== Send email to <fwp-request@technofile.org> with message _body_ ==== unsubscribe