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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
mmcwAuthor Commented:
Array @test contains: value1 value2
Array @test2 contains: value1 value2 value3 value4

Array @test3 contains then must contain: value3 value4
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

prakashk021799Commented:
@test{@test} = (1) x @test;
@test3 = grep {exists $test{$_} ? undef : $_} @test2;
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.