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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T23:47:34+00:00 2026-05-11T23:47:34+00:00

In Perl 5.10, how do I create and access a hash with scalar keys

  • 0

In Perl 5.10, how do I create and access a hash with scalar keys whose values are arrays?

#Doing this does not work properly.
%someHash= ("0xfff" => ('Blue', 'Red', 'Yellow'));
@arr = @fileContents{"0xfff"};
print @arr;

When I print the array, the only thing that prints is “ARRAY(‘randmemAddr’)”. When I do a foreach loop on @arr, only the first element is printed. I have then concluded that I have not stored the array properly in the hash.

  • 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-11T23:47:35+00:00Added an answer on May 11, 2026 at 11:47 pm

    My original answer posted working code, but didn’t really explain the problem with yours. This is expanded a bit to correct that. Your example had two problems. First, you had a problem when making the reference. You need to use [ ] instead of the standard parentheses in order to create a reference (to an anonymous array). Second, when you tried to get at the reference, you left off one set of brackets. You want to put the reference itself inside @{ } in order to get at the whole array. (Also, and this may be a typo: you have no $ before filecontents.)

    The code here is essentially from perldoc perldsc. I highly recommend it. Also very useful if you’re new to references in Perl is perldoc perlreftut. Both tutorials discuss how to make and get at references in a variety of situations. Finally, you can find a good cheat sheet for references in a post on PerlMonks.

    #!/usr/bin/env perl
    use strict;
    use warnings;
    
    
    my %HoA = (
        flinstones      => [ qw/fred barney/ ],
        jetsons         => [ qw/george jane elroy/ ],
    );
    
    for my $family (keys %HoA) {
        print "Members of the \u$family:\n";
        print "\t @{ $HoA{$family} }\n";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to create XML in Perl. From what I read, XML::LibXML is great
Perl has OOP features, but they are somewhat rarely used. How do you create
What is the best way to create a lock on a file in Perl?
What is a good way to create and read an OpenOffice spreadsheet in Perl?
I'm using ActiveState Perl on Windows Server 2003. I want to create a directory
I have written a small Perl script and now I would like to create
Perl and PHP do this with backticks. For example, $output = `ls`; Returns a
After going through couple of linksI came to know that Perl does the compilation
My task is to create a parent-child hierarchy file using perl. Sample Input file
CPAN has the Template::Declare package. A declarative way to create HTML templates in Perl

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.