Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Need advice on checking two hashes values and keys

by Random_Walk (Prior)
on Jun 04, 2015 at 14:40 UTC ( [id://1129058]=note: print w/replies, xml ) Need Help??


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 :-) but perhaps we should looks at the real application as being learning Perl...

/usr/bin/perl use strict; use warnings; my @numbers = ( [qw( Italian Spanish French English Welsh )], [qw( uno uno un one un )], [qw( due dos deux two dau )], [qw( tre tres trois three tri )], [qw( quattro quatro quatre four pedwar )], [qw( cinque cinco cinq five pump )], [qw( sei seis six six chwech )], [qw( sette siete sept seven saith )], [qw( otto ocho huit eight wyth )], [qw( nouve nueve neuf nine naw )], [qw( dieci diez dix ten deg )], ); 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 out 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.

Pereant, qui ante nos nostra dixerunt!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1129058]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2024-04-25 17:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found