Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

filter data from 2 array

Status
Not open for further replies.

edwardsal

Technical User
Nov 3, 2006
13

how I can filter only data that = I want from 2 array?

I have to array

@array1=("1","2","3");
@array2=("1");

so how I can make if statment if some element from array1=array2 than true else false?
 
Might have to put a few more words around that. Do you mean that for each element n you want to compare $array1(n) with $array2(n) ?

Or do you want to check to see if $array1(n) can be found anywhere in @array2 ?

Post what you have so far, as well, as this might give a clearer indication of what you want...

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
Code:
my @a1=("1","2","3");
my @a2=("1");

my @conditionals = map {defined $a1[$_] && defined $a2[$_] && $a1[$_] eq $a2[$_]} (0..($#a1> $#a2? $#a1: $#a2))

# @conditionals equals (1, '', '')

I doubt this is really want you want. You were extremely unclear and honestly sounded drunk in your description. But if you really are drunk, then you won't notice when this code isn't what you want, and will give me a star anyway.

Cheers! [party]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top