in reply to Using Positions from one array to find the value in the same position of another.
Building on the ideas of NetWallah and choroba:
c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le "my @dict = ('???', qw(a abbey zymophore zymophoric)); ;; my %encode = map { $dict[$_] => $_ } 0 .. $#dict; dd \%encode; ;; chomp(my $sentence = <STDIN>); print qq{sentence: '$sentence'}; my @words = split ' ', lc $sentence; dd \@words; ;; my @encoding = map { $encode{ exists $encode{$_} ? $_ : '???' } } @wo +rds; dd \@encoding; ;; my @decoding = @dict[ @encoding ]; dd \@decoding; " { "???" => 0, "a" => 1, "abbey" => 2, "zymophore" => 3, "zymophoric" = +> 4 } a crumbling zymophoric abbey sentence: 'a crumbling zymophoric abbey' ["a", "crumbling", "zymophoric", "abbey"] [1, 0, 4, 2] ["a", "???", "zymophoric", "abbey"]
Give a man a fish: <%-{-{-{-<
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Using Positions from one array to find the value in the same position of another.
by RuZombieSlayer (Novice) on Apr 29, 2016 at 21:19 UTC | |
by AnomalousMonk (Archbishop) on Apr 29, 2016 at 21:32 UTC |