Friday, December 31, 2010

Compare two arrays and create third array

my @first=(1..30);
my @second=qw(5 8.1 9.1 9.2 10 15 21.5 21.9 2.1);

my $i=1;
foreach $num (@first) {
    push(@new, $num);
    foreach $c (@second) {
        if((!(grep /$c/, @first)) and ($c > $num) and ($c < $num+1)){
            push(@new, $c);
        }
=start
        elsif($c == $num) {
        #print "$num: match array\n";
        }
=cut
    }
$i++;
}
print $_, "\n" foreach (@new);

No comments: