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 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 am completely new to SQLite and I intend to use it in a
Let's consider the following XML Schema: <?xml version=1.0 encoding=UTF-8?> <schema targetNamespace=http://www.example.org/library elementFormDefault=qualified xmlns=http://www.w3.org/2001/XMLSchema xmlns:lib=http://www.example.org/library>
public IEnumerable GetActive() { return Session.CreateQuery(from Agency where active=true order by agencyname).List(); } Obviously,
I'm trying to port some old MySQL queries to PostgreSQL, but I'm having trouble
I'm having a go at writing my own toy OS and for the moment
I am doing multiple HTTP POST to a REST web service that I created.
I've come to the point where I need to store some additional data about
I'm curious if this is even possible with Regex. I want to extract tokens
I'm building an autoloader that extends the include_path. It takes an array, appends the
I have flat file schema (description below), I am getting flat file(description below) through

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.