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 7652081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:40:22+00:00 2026-05-31T11:40:22+00:00

Is it possible in Perl to access a value of a hash, if it

  • 0

Is it possible in Perl to access a value of a hash, if it has just one key, without using key value?

Let’s say, %h has just 'key_name' => 'value'.

Can I access the 'value' only via $h->{key_name}?

Or, is possible to access this 'value' without key name?

  • 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-05-31T11:40:24+00:00Added an answer on May 31, 2026 at 11:40 am

    The values builtin function for hashes will return a list of all the hash values. You can use this to get or set any values with aliasing list constructs such as foreach, map, and grep:

    for my $value (values %hash) {
        say $value;  # prints the value
        $value++;    # adds one to the value
    }
    

    Or you can store the values in an array:

    my @vals = values %hash;
    

    The order of the returned values is effectively random, but it will be the same order as the corresponding keys function.

    Hashes themselves are lists, so you can access any odd element of the hash in list context to get at the value, but this method is less efficient since the whole hash needs to be taken apart to form the list, not just the values.

    The techniques above work with hashes of any size. If you only have one key / value pair:

    my %hash = qw(foo bar);
    

    Then they reduce to:

    {my ($x) = values %hash;    say $x} # bar
    {my (undef, $x) = %hash;    say $x} # bar
    {my $x = (values %hash)[0]; say $x} # bar
    {my $x = (%hash)[1];        say $x} # bar
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to access the same value under different hash keys? How can
Is it possible to access value of a global variable declared, in another perl
I know this is possible in Perl, but I was wondering if this can
Possible Duplicate: Comparing Two Arrays Using Perl I am trying to find elements that
Is it possible to save some Perl code in a database, retrieve it using
I know it is possible to create classes/objects in Perl using the bless function
Is it possible to find the crop marks in PDF files using Perl code?
Using any of the iPhone's private APIs, is it possible to access the call
Possible Duplicate: Perl + POO and “Can't call method ”prepare I learned poo and
Is it possible in Perl to install only one signal handler for all the

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.