### Re: How can one find unique elements from arrays using a LOOP?

by choroba (Cardinal)
 on Mar 04, 2014 at 10:58 UTC Need Help??

You are assigning a single element to an array, namely a value from a (non-existent) hash:
```@arr = \$p{\$num};

Using strict would have told you.

Also,

```push @p, @x;
push @p, @y;

is effectively the same as

```push @p, \$_ for @x, @y;

Why are you pushing array references in the first example, but arrays in the second one?

لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^2: How can one find unique elements from arrays using a LOOP?
by pajout (Curate) on Mar 04, 2014 at 11:05 UTC
Simply
```push @p, @x, @y;
:)
I had the feeling the OP might still understand that as
```push @p, \@x, \@y
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re^2: How can one find unique elements from arrays using a LOOP?
by supriyoch_2008 (Monk) on Mar 04, 2014 at 12:30 UTC

Hi choroba,

Thank you for your suggestions and prompt reply. My problem appears to be solved. Your last sentence (question) has been very constructive and ignited my thinking. It has helped me to sort out the problem. I have corrected the script m.pl and it goes as follows. I am grateful to you.

With regards,

Here goes the code m.pl:

```#!/usr/bin/perl
use warnings;

use List::Compare;   # Use of module

@x= qw/a b/;
@y= qw/a c/;
@z= qw/a d/;

push @s,\@x,\@y,\@z;

\$num_ele=@s;

print "\n
Array s: @s\n
No. of Elements: \$num_ele\n";

\$all= List::Compare->new(@s); # module

@unq_x=\$all->get_unique(0);
@unq_y=\$all->get_unique(1);
@unq_z=\$all->get_unique(2);

print "
unq_x: @unq_x\n
unq_y: @unq_y\n
unq_z: @unq_z\n\n";

exit;

The results of m.pl are (correct):

```C:\Users\x\Desktop>m.pl

Array s: ARRAY(0x320b14) ARRAY(0x320b64) ARRAY(0x3305d4)

No. of Elements: 3

unq_x: b

unq_y: c

unq_z: d

Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1076851]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (2)
As of 2024-05-26 20:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?

No recent polls found