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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:27:41+00:00 2026-05-27T14:27:41+00:00

I noticed a hash object was once defined as in the following: my %data

  • 0

I noticed a hash object was once defined as in the following:

 my  %data = ();
 $data{file}  = $file;
 $data{concept} = $#row;
 $data{line1} {$cell[0]} = $cell[1];

What does this hash construction process try to achieve? Or what is the difference between

$data{concept} = $#row;

and

$data{line1} {$cell[0]} = $cell[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-05-27T14:27:41+00:00Added an answer on May 27, 2026 at 2:27 pm
    #!/usr/bin/perl
    use strict;
    use warnings;
    use Data::Dumper;
    
    my $file = "contents of my file";
    my @row = qw(some random data);
    my @cell = qw(key value);
    
    my %data = ();
    $data{file}  = $file;
    $data{concept} = $#row;
    $data{line1} {$cell[0]} = $cell[1];
    
    print Dumper \%data;
    

    Output:

    $VAR1 = {
          'file' => 'contents of my file',
          'line1' => {
                       'key' => 'value'
                     },
          'concept' => '2'
    };
    

    I think $data{line1} {$cell[0]} is better written as $data{line1}{$cell[0]} or (my preference) $data{line1}->{$cell[0]}.

    I included the scalar $file and the arrrays @row and @cell to demonstrate what your code means.

    $data{file} = $file;
    

    adds the contents of $file to your hash with the key file.

    $data{concept} = $#row;
    

    adds the last index of @row to your hash with the key concept. In my example the last index is 2, since the indexes in @row are 0, 1 and 2.

    $data{line1} {$cell[0]} = $cell[1];
    

    adds a hash ref to your hash with the key line1 (through autovivification) and adds the element $cell[1] to this hash ref with the key $cell[0]. Autovivification in this case means that Perl associates line1 with a hash ref and creates it, because you’re accessing it with {$cell[0]}. That saves you the trouble of having to write:

    $data{line} = {};
    $data{line}{$cell[0]} = $cell[1];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Noticed this today when a patch was submitted with the following line: lblCompletionTime.Text =
If I notice that a hash table (or any other data structure built on
I noticed that you can call Queue.Synchronize to get a thread-safe queue object, but
I noticed that my Designer.vb file of one of my forms has a lot
I see this referenced a lot: http://ajaxify.com/run/crossframe/ And I noticed now it's no longer
This bug may be lurking since the beginning of ruby-mode , but I noticed
I've noticed some strange behaviour in JS window.location.hash = ''; var hash = window.location.hash;
I have the following code in an Active Record file. class Profile < ActiveRecord::Base
Yesterday morning I noticed Google Search was using hash parameters: http://www.google.com/#q=Client-side+URL+parameters which seems to
I noticed that mongodb allows for ordered hash, but i do not see documentation

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.