Re: multidimensional array assignment



"ronak" <ronak.vlsi@xxxxxxxxx> writes:

@str=@temp;

This is a shallow copy. @temp is an array of references to
arrays. After the copy, @str will contain references to the same
arrays: @str and @temp are different arrays, but $str[$mm] refers
to the same array as $temp[$mm] does. So, when the next iteration
modifies $temp[$mm][$l], it is also modifying $str[$mm][$l].

I suppose the easiest way to construct new second-level arrays is:

@str = map [@$_], @temp;

If you want an even deeper copy, the Clone module might do the job.
.



Relevant Pages

  • RE: [ Hash of Arrays]
    ... I want to use Hash of Arrays. ... #retrieve the values and assign to ... #@temp by dereferencing the hash key ...
    (perl.beginners)
  • Re: Problem on Array with C!
    ... A very commom mistake is that you forgot that arrays start with 0 and ... not one hence when you run that for loop you over run the array now to ... exchange values make a var called temp and change it by code like this ...
    (comp.programming)
  • Re: CString and array.
    ... istringstream istr; ... Then don't use arrays, ... istr>> temp; ...
    (comp.lang.cpp)
  • Re: sum two arrays by indexes
    ... Gerard Matthew wrote: ... > I'm looking for a short way of suming the indexes of two arrays and ... > return $temp; ...
    (comp.lang.php)
  • Re: Confused by a c-faq example
    ... In this code, str is a function parameter, so its declaration is ... str is a pointer (of type char *), and it is legal to assign to it. ... It is only to show that there are cases where arrays can be ...
    (comp.lang.c)