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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:31:40+00:00 2026-05-16T06:31:40+00:00

How can I preserve the order in which the hash elements were added FOR

  • 0

How can I preserve the order in which the hash elements were added
FOR THE SECOND VAR ?

( Hash of Hashes )

For example:

use Tie::IxHash;
my %hash;
tie %hash, "Tie::IxHash";
for my $num (0 .. 5){
     $hash{"FirstVal$num"}++;
}
for my $num (0 .. 5){
     $hash{"FirstValFIXED"}{"SecondVal$num"}++;
}
 print Dumper(%hash);

When dumping out the result, $VAR14 didn’t preserve the insertion order:

$VAR1 = 'FirstVal0';
$VAR2 = 1;
$VAR3 = 'FirstVal1';
$VAR4 = 1;
$VAR5 = 'FirstVal2';
$VAR6 = 1;
$VAR7 = 'FirstVal3';
$VAR8 = 1;
$VAR9 = 'FirstVal4';
$VAR10 = 1;
$VAR11 = 'FirstVal5';
$VAR12 = 1;
$VAR13 = 'FirstValFIXED';
$VAR14 = {
           'SecondVal5' => 1,
           'SecondVal4' => 1,
           'SecondVal2' => 1,
           'SecondVal1' => 1,
           'SecondVal3' => 1,
           'SecondVal0' => 1
         };

I know I can trick that example with some sort operation but in my real problem the elements are not numbered or can’t be ordered some how.
Is there any simple function/operation for hash multi level order insertion ?

Thanks,

Yodar.

  • 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-16T06:31:41+00:00Added an answer on May 16, 2026 at 6:31 am
    foreach my $sortline (sort {$a<=>$b} keys %{$hash->{"first_field"}}){
        my $name;
        # Soultion to touch a Key with keys within it:
        #--------------------------------------------- 
        foreach my $subkey (keys %{$hash->{"first_field"}->{$sortline}})
                {$name = $subkey;}
        #---------------------------------------------
    }
    

    This useful answer helped me.

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

Sidebar

Related Questions

I have generic list which must be a preserved order so I can retrieve
How can you preserve enters given by the user in the database and show
How can I preserve the states of checkbox using session? I tried the following
I want to preserve Ripple effect on my UIImageView. I know we can animate
Can I order my users in the database, so I don't have to say
Given a DAG, in which each node belongs to a category, how can this
Which of the following collection types do you use in your JPA domain model
How can i Plot an array in a graph against its order in array
Is there any way by which I can add the new key-value pairs to
I'm dynamically loading User Controls into a div, which I need to preserve on

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.