Detect difference between two variables

Hello,

I have to variables:
@test
and
@test2

What I want to do is to detect the difference between variable @test and @test2 and write it to @test3

How to so that ??

greetings Michel
mmcwAsked:
Who is Participating?
 
prakashk021799Connect With a Mentor Commented:
@test{@test} = (1) x @test;
@test3 = grep {exists $test{$_} ? undef : $_} @test2;
0
 
MindoCommented:
Tell us what particularly do you have in these arrays and what difference results do you want to get?
0
 
monasCommented:
do you mean arithmetical difference between coresponding members of these two arrays,
or do you want to get @test3 hold values of @test and/or @test2 what are not the same at particular index?
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
mmcwAuthor Commented:
Array @test contains: value1 value2
Array @test2 contains: value1 value2 value3 value4

Array @test3 contains then must contain: value3 value4
0
 
ozoCommented:
perldoc -q "How do I compute the difference of two arrays"
0
 
mmcwAuthor Commented:
Questiion to OZO:

What do I do with that perldoc command.
Where do I ask that qoustion????
0
 
prakashk021799Commented:
Enter that command at the command prompt in your shell.
0
 
ozoCommented:
#prakashk, your grep would be better as
@test3 = grep { !$test{$_} } @test2;
#as it is, it would skip a "0" value in @test2
0
 
prakashk021799Commented:
Yep. Thanks for catching it, Ozo.

It could however be rewritten to catch this special case by adding 'defined':

@test3 = grep {exists $test{$_} ? undef : defined $_} @test2;
0
 
mmcwAuthor Commented:
Question about perldoc:

I do not have tellnet access!!
0
All Courses

From novice to tech pro — start learning today.