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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:31:21+00:00 2026-05-10T22:31:21+00:00

I have a program in Perl I’m working on where I would need multiple

  • 0

I have a program in Perl I’m working on where I would need multiple keys, and a way of giving each key multiple values and follow that by being able to both read them in and write them out to an external file depending on if the key matches what the person enters into standard input. I’ve looked across several sites and have found information somewhat useful in reading in hashes of arrays, but not writing them out, and I would also need to be able able to add to the array in the external file.

Is this possible?

Edit: Is there a way that it could be done with starter Perl? I’m a beginner. Hashes of arrays seemed like the best way to make it work, but what I really need is a way to show multiple values for the same key while only showing the key once.

  • 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. 2026-05-10T22:31:21+00:00Added an answer on May 10, 2026 at 10:31 pm

    Check out Data::Dumper.

    For instance, this microscopic script:

    #!/bin/perl -w use strict; use Data::Dumper;  my(%hash);  $hash{key1} = [ 1, 'b', 'c' ]; $hash{key2} = [ 4.56, 'g', '2008-12-16 19:10 -08:00' ];  print Dumper(\%hash); 

    produces this output, which could clearly be edited:

    $VAR1 = {           'key2' => [                       '4.56',                       'g',                       '2008-12-16 19:10 -08:00'                     ],           'key1' => [                       1,                       'b',                       'c'                     ]         }; 

    It can also be evaluated to read the data back into the program.


    Extending the example to show reading in as well as printing out…Note that the code is in two main blocks, and the only variable common between the blocks is the name of the file.

    #!/bin/perl -w use strict; use Data::Dumper; use FileHandle;  my $file = 'data.out';  {     my(%hash);      $hash{key1} = [ 1, 'b', 'c' ];     $hash{key2} = [ 4.56, 'g', '2008-12-16 19:10 -08:00' ];      my $str = Data::Dumper->Dump([ \%hash ], [ '$hashref' ]);     print 'Output: $str';      my($out) = new FileHandle '>$file';     print $out $str;     close $out; }  {     my($in) = new FileHandle '<$file';     local($/) = '';     my($str) = <$in>;     close $in;      print 'Input: $str';      my($hashref);     eval $str;     my(%hash) = %$hashref;      foreach my $key (sort keys %hash)     {         print '$key: @{$hash{$key}}\n';     } } 

    The output from that script is:

    Output: $hashref = {          'key2' => [                      '4.56',                      'g',                      '2008-12-16 19:10 -08:00'                    ],          'key1' => [                      1,                      'b',                      'c'                    ]        }; Input: $hashref = {          'key2' => [                      '4.56',                      'g',                      '2008-12-16 19:10 -08:00'                    ],          'key1' => [                      1,                      'b',                      'c'                    ]        }; key1: 1 b c key2: 4.56 g 2008-12-16 19:10 -08:00 

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

Sidebar

Ask A Question

Stats

  • Questions 75k
  • Answers 75k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Well, by a process of trial and error, it appears… May 11, 2026 at 2:47 pm
  • added an answer Have you seen Selenium ? You can automate your browser-side… May 11, 2026 at 2:47 pm
  • added an answer Some more details from MSDN: The prefix "@" enables the… May 11, 2026 at 2:47 pm

Related Questions

I have a program in Perl I'm working on where I would need multiple
I am writing a small program in Perl for my assignment and I am
I'm trying to gain some memory saving in a C++ program and I want
I have a C program with an embedded Perl interpreter. I want to be
I am trying to write a regex expresstion in mysql from a Perl program.

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.