Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Need advice on checking two hashes values and keys

by Random_Walk (Prior)
on Jun 04, 2015 at 14:40 UTC ( [id://1129059]=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 :-)

/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.

Pereant, qui ante nos nostra dixerunt!

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

    I enjoyed your program and finding out what happens when uno is typed

    meant to tell you earlier but I now using your program to learn and practice other little stuff in perl. thanks!

      Hi perlynewby,

      Thanks for the feedback. Nice to know I was of some help.

      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://1129059]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (2)
As of 2024-04-19 19:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found