in reply to Need advice on checking two hashes values and keys
Here is one without the hash, using a table. It does make me think a database would be better for this application :-)
/usr/bin/perl use strict; use warnings; my @numbers = ( [qw( Italian Spanish French )], [qw( uno uno un )], [qw( due dos deux )], [qw( tre tres trois )], [qw( quattro quatro quatre )], [qw( cinque cinco cinq )], [qw( sei seis six )], [qw( sette siete sept )], [qw( otto ocho huit )], [qw( nouve nueve neuf )], [qw( dieci diez dix )], ); print "Please enter number to translate\n"; my $num = <>; while ($num) { print "You typed $num\n"; chomp $num; for my $row (@numbers) { # dereference array, and look for our number in it next unless grep {/$num/} @$row; print "I found it: "; print join " <-> ", @$row; print "\n"; my $i = 0; $i ++ until $row->[$i] eq $num; print "It looks like it was in $numbers[0]->[$i]\n"; last; } print "Please enter another number to translate\n"; $num = <>; }
The question this raises, is what happens when you type in uno? Altering it to know when a number has multiple matches, is left as an exercise for the reader.
Cheers,
R.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Need advice on checking two hashes values and keys
by perlynewby (Scribe) on Sep 18, 2015 at 00:59 UTC | |
by Random_Walk (Prior) on Oct 01, 2015 at 08:39 UTC |