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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:41:49+00:00 2026-06-13T06:41:49+00:00

I have an array. The elements in the array are containing semi colon in

  • 0

I have an array. The elements in the array are containing semi colon in between them.

Array looks something like this:

@Array = { "AUT;E;1",
           "AUT;E;2",
           "CHE;A;1",
           "CHE;C;4"
         };

I want to split the array elements using ‘;’ (semicolon) as delimiter.

By using hash of hashes I want to store ‘AUT’ as key and under that want to store E => 1 and E => 2.

i.e I needed the hash as

%HashOfElem = (
         'AUT' => {
                     'E' => 1,
                     'E' => 2
                  },

         'CHE' => {
                     'A' => 1,
                     'C' => 4
                  }
              )

For that purpose I wrote the following code which is not behaving as expected 🙁

foreach(@Array)
{
    my @TmpArray = split(/;/,$_);

    %HashOfElem = (
              $TmpArray[0] => {
                                  $TmpArray[1] => $TmpArray[2]
                              }
                  );

}

If my approach is wrong then which data structure in perl can be used to achieve above purpose?

Please help..

  • 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-13T06:41:50+00:00Added an answer on June 13, 2026 at 6:41 am

    Note that you’re doing wrong assignement to @Array, it should be (parenthesis instead of braces):

    updated according to comment:

    my @array = (
        "AUT;E;1",
        "AUT;E;2",
        "CHE;A;1",
        "CHE;C;4"
    );
    

    so your script becomes:

    my @array = (
        "AUT;E;1",
        "AUT;E;2",
        "AUT;E;2",
        "CHE;A;1",
        "CHE;C;4"
    );
    my %hash;
    my %dups;
    foreach (@array) {
        next if exists $dups{$_};  # skip this line if already stored
        $dups{$_} = 1;
        my @tmp = split/;/;
        push @{$hash{$tmp[0]}{$tmp[1]}}, $tmp[2];
    }
    say Dumper\%hash;
    

    output:

    $VAR1 = {
              'CHE' => {
                         'A' => [
                                  '1'
                                ],
                         'C' => [
                                  '4'
                                ]
                       },
              'AUT' => {
                         'E' => [
                                  '1',
                                  '2'
                                ]
                       }
            };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array list containing few elements. What i want to do is
I have an array.. [1,2,3,4] and I want a string containing all the elements
Consider I have an array of elements out of which I want to create
VISUAL C++ Question Hi, I have array of 3 elements and I want to
I have an array with 16 elements. I would like to evaluate these to
An array is defined of assumed elements like I have array like String[] strArray
I have an Array that contains some elements multiple times. Now I want to
I have a vector/array of n elements. I want to choose m elements. The
I want to use longjmp to simulate goto instruction.I have an array DS containing
In PHP I have an array containing 20 elements or more. The keys have

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.