in reply to Identifying bigrams and making a note of which ones exist

Well, first, we can make @bigram like this:

@bigram = ( 'aa' .. 'zz' ); # magic!

Next, do the searching and remembering (this is just one way to do it):

# make a "set" of the ones in the list: my %bigram_list; @bigram_list{@bigram_list} = (); # corresponds to (and same size as) @bigram. my @bigrams_existing = map { exists $bigram_list{$_} ? 1 : 0 } @bigram;
We're building the house of the future together.

Replies are listed 'Best First'.
Re^2: Identifying bigrams and making a note of which ones exist
by GrandFather (Saint) on Mar 10, 2006 at 21:06 UTC

    Fleshing your code out a little into a full example gives:

    use strict; use warnings; use Data::Dump::Streamer; my @bigram = ( 'aa' .. 'zz' ); # magic! my @testBigrams = split ' ', do {local $/; <DATA>;}; # make a "set" of the ones in the list: my %bigram_list; @bigram_list{@testBigrams} = (0) x @testBigrams; # corresponds to (and same size as) @bigram. my @bigrams_existing = map { exists $bigram_list{$_} ? 1 : 0 } @bigram; Dump (\@bigrams_existing); __DATA__ gr an df at he rj dp or te rj kv ap la ne ts ca pe ww

    Note in particular that the line @bigram_list{@bigram_list} = (); becomes @bigram_list{@testBigrams} = (0) x @testBigrams; and starts to make some sense.


    DWIM is Perl's answer to Gödel