Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^2: Print/Lookup from array element to another array element

by Dr Manhattan (Beadle)
on Apr 07, 2013 at 09:53 UTC ( #1027344=note: print w/replies, xml ) Need Help??


in reply to Re: Print from array element to another array element
in thread Print from array element to another array element

Hi Loops

I used the 'say' feature and it works correctly. My next question is- How do I lookup from one element in a array to another one?

For instance the word "food" is a element in a hash. I want to lookup and if the combined elements of my array exists in the hash it should be printed

I tried this-

if (exists $hash{@array[3..$end]}) { say @array[3..$end]; }

Replies are listed 'Best First'.
Re^3: Print/Lookup from array element to another array element
by choroba (Chancellor) on Apr 07, 2013 at 09:59 UTC
    The keys in a hash are always strings. You cannot use an array slice as a hash key. You have to join the list to form a string:
    exists $hash{ join q(), @array[3 .. $end] }
    لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re^3: Print/Lookup from array element to another array element
by RichardK (Parson) on Apr 07, 2013 at 11:53 UTC

    If you want to find one string inside another, just use index

    So, something along these lines :-

    my $text ='catfood'; # returns -1 if not found say index($text,'food',0);
Re^3: Print/Lookup from array element to another array element
by Anonymous Monk on Apr 07, 2013 at 10:02 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1027344]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2016-12-05 10:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (80 votes). Check out past polls.