in reply to Search hash keys using values from array

G'day AhmedABdo,

This looks like an "XY Problem" to me. In addition, it looks like you've typed, rather than pasted, your code, which has resulted in typos: My should be my; "Hello" is either missing from @array, extraneous to %hash, or an explanation of how it relates to the rest of your post has been omitted. I see others have already pointed out further issues: I won't repeat those comments here but I do agree with them.

Perhaps what you're looking for can be achieved with the enum module. Here's a script with a couple of examples of usage:

#!/usr/bin/env perl -l use strict; use warnings; use enum qw{world=1 today is nice}; print '"world today" from enum'; print for world, today; print '"today is nice" from array'; my @indices = (today, is, nice); print for @indices;

Output:

"world today" from enum 1 2 "today is nice" from array 2 3 4

— Ken

Replies are listed 'Best First'.
Re^2: Search hash keys using values from array
by thanos1983 (Parson) on Mar 24, 2017 at 11:07 UTC

    Hello kcott,

    In this case enum fits perfect. Thanks for pointing out, I had no idea about it.

    Seeking for Perl wisdom...on the process of learning...not there...yet!

      Glad you liked it.

      Here's another, more complex example of usage, that I posted last month. This shows a method of determining the original token name from the index.

      — Ken