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

  • Home
  • SEARCH
  • 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 8914203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:39:39+00:00 2026-06-15T04:39:39+00:00

How do I set a list of scalars from a perl hash? use strict;

  • 0

How do I set a list of scalars from a perl hash?

use strict;
my $my_hash = { field1=>'val1', field2=>'val2', field3=>'val3', };
my ($field1,$field2,$field3) = %{$my_hash}{qw(field1 field2 field3)};

print "field1=$field1\nfield2=$field2\nfield3=$field3\n";
  • 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-15T04:39:40+00:00Added an answer on June 15, 2026 at 4:39 am

    You’re looking for a hash slice which in your case would look like this:

    my ($field1,$field2,$field3) = @{$my_hash}{qw(field1 field2 field3)};
    

    or like this:

    my ($field1,$field2,$field3) = @$my_hash{qw(field1 field2 field3)};
    

    If we simplify things so that you’re working with a straight hash rather than hash-ref, we can remove some of the noise and the syntax will look a bit clearer:

    my %my_hash = ( field1=>'val1', field2=>'val2', field3=>'val3' );
    my ($field1, $field2, $field3) = @my_hash{  qw(field1 field2 field3)  };
    # we want an array/list ---------^       ^  ^
    # but my_hash is a hash -----------------/  |
    # and we want these keys (in this order) ---/
    # so we use a qw()-array
    

    Then we can get to your $my_hash hash-ref version by replacing the hash with a hash-ref in the usual way.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to read lines from a file into a Set or List. Is
I would like to convert from a set to a List within a method
I was trying to use LINQ to set some values in my list, but
Is there any way in my .vimrc file to use the command set list!
Suppose I have a list (or Set): List<String> testList = Lists.newArrayList(assocX,srcT,destA,srcX, don't care Y,
I have two list: set lista {5 6} set listb {8 9} and the
I have a set of list items in unordered lists that I bind the
I have a UL List set up as follows: <div id=menu> <ul> <li> <a
I am using Drupal and have sifr set on list items, and also a,
I have a ListActivity and in it I set my list items with a

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.