Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7818295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:32:03+00:00 2026-06-02T06:32:03+00:00

I am looking for search implementation on hash using perl. I have following data

  • 0

I am looking for search implementation on hash using perl. I have following data in my hash

%hash = {0 => "Hello", 1=> "world"}. 

Now i want to search the hash using the values (means world and hello) and return corresponding key.

Example: I want to search for world and the result should be 1

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T06:32:05+00:00Added an answer on June 2, 2026 at 6:32 am

    Iterate of the keys of the hash with a for ( keys %hash ) ... statement and check the values as you go. If you find what you are looking for, return

    my $hash = { 0 => "World", 1 => "Hello" };
    
    for ( keys %$hash ) {
        my $val = $hash->{$_};
        return $_ if $val eq 'World'; # or whatever you are looking for
    }
    

    another option would be to use while ( ... each ... )

    my $hash = { 0 => "World", 1 => "Hello" };
    
    while (($key, $val) = each %$hash) {
        return $key if $val eq 'World'; # or whatever you are looking for
    }
    

    the use of { } literal creates a hash reference and not a hash

    $h = { a => 'b', c => 'd' };
    

    to create a literal hash you use ( )

    %h = ( a => 'b', c => 'd' );
    

    execution of while ... each on hashref

    $h = { a => 'b', c => 'd' };
    print "$k :: $v\n" while (($k, $v) = each %$h );  
    
    c :: d
    a :: b
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im looking for something like a search and replace functionality in Solr. I have
The functionality I'm looking for: I have a form that will search my 'Proposal'
I'm working on a fairly specialized search engine implementation in Perl, it searches (by
I'm looking for a KDTree implementation in Java. I've done a google search and
I was just looking through implementation of non local means algorithm via google (thanks
I'm looking for a fuzzy search implementation that works well with western European languages.
I'm looking for a built-in Binary Search Tree implementation in .NET 4. Is there
I'm looking to build a powerful search feature for a site, similar to NewEgg's
While looking for a way to temporarily save the search results when a user
I'm looking for a way to search a file system that contains approximately 1TB

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.