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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:56:13+00:00 2026-05-23T04:56:13+00:00

I am having some problem with my perl. I hashed a key to an

  • 0

I am having some problem with my perl. I hashed a key to an array. Now I want to change things in the array for each key. But I can’t find out how this works :

open(DATEBOOK,"<sample.file");

@datebook = <DATEBOOK>;

$person = "Norma";

foreach(@datebook){
    @record = ();
    @lines = split(":",$_);

        $size = @lines;
        for ($i=1; $i < $size; $i++){
            $record[$i-1] = $lines[$i];
        }
    $map{$lines[0]}="@record";  

}

for(keys%map){ print $map{$_}};

The datebook file :

Tommy Savage:408.724.0140:1222 Oxbow Court, Sunnyvale,CA 94087:5/19/66:34200
Lesle Kerstin:408.456.1234:4 Harvard Square, Boston, MA 02133:4/22/62:52600
JonDeLoach:408.253.3122:123 Park St., San Jose, CA 94086:7/25/53:85100
Ephram Hardy:293.259.5395:235 Carlton Lane, Joliet, IL 73858:8/12/20:56700
Betty Boop:245.836.8357:635 Cutesy Lane, Hollywood, CA 91464:6/23/23:14500
William Kopf:846.836.2837:6937 Ware Road, Milton, PA 93756:9/21/46:43500
Norma Corder:397.857.2735:74 Pine Street, Dearborn, MI 23874:3/28/45:245700
James Ikeda:834.938.8376:23445 Aster Ave., Allentown, NJ 83745:12/1/38:45000
Lori Gortz:327.832.5728:3465 Mirlo Street, Peabody, MA 34756:10/2/65:35200
Barbara Kerz:385.573.8326:832 Ponce Drive, Gary, IN 83756:12/15/46:268500

I tried $map{$_}[1], but that doesn’t work. Can anyone give me an example on how this works 🙂 ?

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-05-23T04:56:14+00:00Added an answer on May 23, 2026 at 4:56 am

    First, use strict and use warnings. Always.

    Assuming what you want is a hash of arrays, do something like this:

    use strict;
    use warnings;
    
    open my $datebookfh, '<', 'sample.file' or die $!;
    my @datebook = <$datebookfh>;
    
    my %map;
    foreach my $row( @datebook ) { 
        my @record = split /:/, $row;
        my $key = shift @record;   # throw out first element and save it in $key
    
        $map{$key} = \@record;
    }
    

    You can test that you have the correct structure by using Data::Dumper:

    use Data::Dumper;
    print Dumper( \%map );
    

    The \ operator takes a reference. All hashes and arrays in Perl contain scalars, so compound structures (e.g. hashes of arrays) are really hashes of references to arrays. A reference is like a pointer.

    Before going further, you should check out:

    • Perl reference tutorial
    • Arrays of arrays
    • Perl Data Structure Cookbook
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating some UIButton s programmatically in a loop but I'm having some problem
i'm trying to parse some json in perl, but am having problems with it.
I'm having some problem with MKMapView / annotations / UINavigationController. Basically, i manage my
I am working on a windows form project and having some problem with UserControl
I'm having some difficulties with the following problem: I'm making a little game where
I've been having some difficulty in understanding the source of a problem. Below is
I am having some trouble with this code . The problem is when i
Hey, I'm having some difficulty with CSS and IE6 compatibility. URL : http://bit.ly/dlX7cS Problem
I'm new to Ruby, so I'm having some trouble understanding this weird exception problem
I'm having a problem with some code I've written. I've had to anonymize it,

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.