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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:58:38+00:00 2026-06-11T11:58:38+00:00

I have an array @fields containing names for the tab-separated values in $record (it

  • 0

I have an array @fields containing names for the tab-separated values in $record (it may have been populated from record 0 of the file, for instance).

The order of the array entries corresponds to the order of the values in the record.

I want to populate %hash with field => value entries for each value in the record.

Is there a one-liner to do this? I can’t figure out how to coordinate traversing the @fields and split(“\t”, $record) list concurrently.

Best I can come up with is

my %hash;
my @values = split("\t", $record);
for my $field (@fields) {
    my $value = shift @values;
    $hash{$field} = $value;
}

But I suspect there’s a simpler way to do it.

Thanks.

  • 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-11T11:58:40+00:00Added an answer on June 11, 2026 at 11:58 am

    There is — it’s the hash slice notation:

    @values = split /\t/, $record;
    @hash{@fields} = @values;
    

    or

    @hash{@fields} = split /\t/, $record;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a structure array containing fields as structure arrays of varying length. For
I have an array of structs and one of the fields in the struct
Is there any way to obtain Object array of Java Bean fields? I have
I have a category collection and each category has a array of hashes containing
I have an array containing much more items than just this one. This is
I have an array containing friends list of a user on Facebook. I have
This is my situation: I have a text file containing a lot of equal-length
I have an array containing data (ID numbers and data associated with them). The
Background: I'm pulling all of the field names from a database into an array
I have a form containing several fields. One of them is a Datetime field.

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.