in reply to two dimensional array lookup

Two lines are indeed enough.

# Build a hash of word counts foreach ( map @$_, @all ) { $words{$_} ++ } # Create a list of arrays showing repeats @out = map { [ map $words{$_} > 1 ? 1 : 0, @$_ ] } @all;

With regards to map, I find it easiest to think of it as a rolled-up form of the common foreach ... push idiom:

# List processing with foreach/push foreach ( @input ) { push @out, lc($_); } print @out; # Equivalent "rolled-up" map expression: print map { lc($_) } @input;

Replies are listed 'Best First'.
Re: Re: two dimensional array lookup
by Skeeve (Parson) on Jul 17, 2003 at 06:26 UTC
    ++ because It took me some time to figure out how your solution works.