Re: question on reference to array slice



On Jul 29, 6:09 pm, Mirco Wahab <wahab-m...@xxxxxx> wrote:
John W. Krahn wrote:
$data[ 0 ] = [ \@nums[ 0 .. 9 ] ];
$data[ 1 ] = [ \@nums[ 10 .. 19 ] ];

This usage of slice reference is something I
didn't consider. So Bellovins word was right
again: "any software problem can be solved by
adding another layer of indirection."

"anonymous slice reference" - thanks
for pointing me on this.

I wouldn't call it a slice reference. An array slice is a list. The
\ operator applied to a list returns a list of references of the items
in that list. That is:

my @refs = \($a, $b, $c);
is the same as
my @refs = (\$a, \$b, \$c);

So in John's example, you're assigning $data[0] to be a reference to
an array which contains references to each of the first ten elements
of @nums. There is nothing intrinsic about $data[0][2] that
identifies it as a reference to the element immediately prior to
$nums[3]. It's just a list of references to values that happened to
all come from the same array.

Paul Lalli

.



Relevant Pages

  • Re: VB-101: Passing Arrays ByVal vs ByRef
    ... changed if an array is passed by Val. ... ' new reference ... As each function creates a new array object, ... 'secondArray' and 'secondArrayCopy'. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Need help with textboxes
    ... The JavaScript 1.5 Reference already states: ... All forms and their children are stored in an array ... use dot notation or object literals. ... No. Bracket property accessors allow their argument to be any string value. ...
    (comp.lang.javascript)
  • Re: Garbage Collection Issues in long-standing services
    ... the pinned array should get unpinned or ... The receive case is done quite well, I do create a 4K buffer and reuse it ... and remove the reference to my wrapper socket class, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: How to give selective access to the methods in a class?
    ... different memory locations at different times. ... The reference still leads to the ... So array resizing ... program pushes certain objects into the circular buffer, ...
    (comp.lang.java.programmer)
  • Re: Perlish map() function
    ... the reference material, the Array constructor was introduced in JavaScript ... evaluation would result in a ReferenceError. ... identifier shows that it is true. ...
    (comp.lang.javascript)