in reply to two dimensional array lookup
Oh, and map executes a block of code for each element in the array, returning an array consisting of the return value from each block of code.#!/usr/bin/perl -w use strict; use vars qw(@all @dup); @all=(["what", "is", "the", "matrix"],["matrix", "reloaded", "is", "no +", "good"]); my(%h1,%h2); # for the two halves of your array grep { $h1{$_}=1 } @{$all[0]}; grep { $h2{$_}=1 } @{$all[1]}; @dup = ( [ map { $h2{$_} ? 1 : 0 } @{$all[0]} ], [ map { $h1{$_} ? 1 : 0 } @{$all[1]} ]); print '([', join(',',@{$dup[0]}), '], [', join(',',@{$dup[1]}), "])\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: two dimensional array lookup
by Skeeve (Parson) on Jul 17, 2003 at 06:31 UTC | |
by ctilmes (Vicar) on Jul 17, 2003 at 10:10 UTC |