No such thing as a small change | |
PerlMonks |
Re: Slice of a multidimensional arrayby BrowserUk (Patriarch) |
on Mar 06, 2003 at 18:04 UTC ( [id://240954]=note: print w/replies, xml ) | Need Help?? |
There are two way of looking at what constitutes a slice of a 2d array--and more for higher dimensions:) In the first veiw, the result is what you would get if you could notionally extend perl's @arr[n..m] syntax to a 2D array: @arr[*][n..m] which might be described as "Give me a new 2d array where each row consists of just the columns n through m of the original array". For your example array, and with n & m set to 1 & 2 respectively, this would result in
The second view, and the one you want, is where the resultant arrays row(s) become 1 (or more) column(s) from the original array. for the same example as above you get
Two functions to produce these
I would use these versions of the two functions as it simplifies the syntax of using them slightly, but prototypes are almost universally condemned.
Examine what is said, not who speaks.
1) When a distinguished but elderly scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong. 2) The only way of discovering the limits of the possible is to venture a little way past them into the impossible 3) Any sufficiently advanced technology is indistinguishable from magic. Arthur C. Clarke.
In Section
Seekers of Perl Wisdom
|
|