Intersectioning arrays 
Author Message
 Intersectioning arrays

Is there a way to make arrays intersect?

Like this (doen't work like I want).



my $scalar=\$array[2];


But is there a way to make it more transparent, like making $scalar and

I tried to fool around with typeglobs but I can't make it work. Is it
possible?

no strict;
$sc1="kkk";
*sc2=*sc1;
$sc2="lll";
print $sc1;

Will work for scalars, but without the possibility to use scoping.
--
/jN



Sat, 15 May 2004 08:47:24 GMT  
 Intersectioning arrays

Quote:

> Is there a way to make arrays intersect?

> Like this (doen't work like I want).



> my $scalar=\$array[2];

No, you can't do it with arrays in pure Perl.  But just wait until I
publish Array::Splice.  Unfortunately I haven't even started writing
it!  But my PAUSE user ID arrived today so I'll be uploading an 'i'
("just an idea") state module RSN.  Array::Splice is a working title
it may end up being called something else.

This module will export a splice() function that does what I think splice()
should have done all along.

use Array::Splice qw( splice ); # Replace inbuilt splice()



Quote:
> But is there a way to make it more transparent, like making $scalar and


You declare lexical scalar aliases like this:

for my $scalar ( $array1[2] ) {
  # $scalar is now alias for $array1[2]

Quote:
}

--
     \\   ( )
  .  _\\__[oo

 .  l___\\
  # ll  l\\
 ###LL  LL\\


Sat, 15 May 2004 19:01:38 GMT  
 Intersectioning arrays


| > Is there a way to make arrays intersect?

| No, you can't do it with arrays in pure Perl.  But just wait until I
| publish Array::Splice.  Unfortunately I haven't even started writing
| it!  But my PAUSE user ID arrived today so I'll be uploading an 'i'
| ("just an idea") state module RSN.  Array::Splice is a working title
| it may end up being called something else.
|
| This module will export a splice() function that does what I think
splice()
| should have done all along.
|
| use Array::Splice qw( splice ); # Replace inbuilt splice()



I really don't get how this differs from inbuild splice, please elaborate.

When I think of it, maybe a module like this could be needed.

use Array::Intersect qw(Intersect);







$array2[0]="NewEl";



Was it something like this you meant?
/jN



Sun, 16 May 2004 13:40:49 GMT  
 Intersectioning arrays

Quote:


> | use Array::Splice qw( splice ); # Replace inbuilt splice()



> I really don't get how this differs from inbuild splice, please elaborate.

Like, duh, the difference is the subject of this thread!  My splice
allows multiple arrays (AVs) to intersect in the sense of containing
the same physical elements (IVs).

With CORE::splice the above statment creates a new IV in $array2[1]
which is a copy of $array1[1].  That is to say $array1[1] eq
$array2[1] and \$array1[1] ne \$array2[1].

With my proposed Array::Splice::splice() it makes another reference to
the existing IV.  In other words \$array1[1] eq \$array2[1].

Note that if you spliced constants or other read-only scalars into an
array you'd get read-only elements in the array.

Quote:
> When I think of it, maybe a module like this could be needed.

> use Array::Intersect qw(Intersect);







> $array2[0]="NewEl";



> Was it something like this you meant?

I don't like your Intersect() function as much as my splice() because
there's nothing it can do that my splice() cannot do and there's more
to learn because it's syntax is not the same as an existing function.

Also I don't like using tied arrays to fake the funtionality - I'd
rather have it for real.

--
     \\   ( )
  .  _\\__[oo

 .  l___\\
  # ll  l\\
 ###LL  LL\\



Sun, 16 May 2004 21:13:54 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. URGENT: Hash in Hash, Array in Array, Array in Hash, Hash in Array

2. array of arrays of arrays

3. Separating array into alphabetical array of arrays

4. Help with Embedding and Arrays of Arrays?

5. Passing arrays of arrays in perlxs

6. arrays of arrays

7. Changing One Array Changes Unrelated Arrays -- Why?

8. (Q) array of associative arrays

9. Dividing an array into individual arrays.

10. Associative array of associate arrays

11. array of arrays?

12. Array of Associative Arrays?

 

 
Powered by phpBB® Forum Software