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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:39:17+00:00 2026-06-09T09:39:17+00:00

I am trying to create an array of hashes with each has being an

  • 0

I am trying to create an array of hashes with each has being an tied, ordered IxHash. When looping through my initial hash, the keys are indeed in order. However, as soon as I push them onto an array, the ordering disappears. I know this is my poor knowledge of what is happening with the hash when it is pushed on the array, but if somebody could enlighten me, it would be much appreciated.

#! /usr/bin/perl -w

use strict;
use Data::Dumper;
use Tie::IxHash;

my @portinfo;

tie (my %portconfig, 'Tie::IxHash',
      'name' => [ 'Name', 'whatever' ],
      'port' => [ 'Port', '12345' ],
      'secure' => [ 'Secure', 'N' ]
      );

print "Dump of hash\n";
print Dumper(%portconfig);

print "\nDump of array\n";
push @portinfo, {%portconfig}; 
print Dumper(@portinfo);

The output of this :-

Dump of hash
$VAR1 = 'name';
$VAR2 = [
          'Name',
          'whatever'
        ];
$VAR3 = 'port';
$VAR4 = [
          'Port',
          '12345'
        ];
$VAR5 = 'secure';
$VAR6 = [
          'Secure',
          'N'
        ];

Dump of array
$VAR1 = {
          'secure' => [
                        'Secure',
                        'N'
                      ],
          'name' => [
                      'Name',
                      'whatever'
                    ],
          'port' => [
                      'Port',
                      '12345'
                    ]
        };
  • 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-09T09:39:19+00:00Added an answer on June 9, 2026 at 9:39 am

    Your code:

    push @portinfo, {%portconfig}; 
    print Dumper(@portinfo);
    

    takes the tied hash %portconfig and places its contents into a new anonymous hash which is then pushed into @portinfo. Thus, you have an anonymous, non-ordered hash in your array.

    What you probably mean to do is

    push @portinfo, \%portconfig; 
    print Dumper(@portinfo);
    

    This pushes a reference to %portconfig into @portinfo, thereby retaining your required ordering.

    Thus:

    #! /usr/bin/perl -w
    
    use strict;
    use Data::Dumper;
    use Tie::IxHash;
    
    my @portinfo;
    
    tie (my %portconfig, 'Tie::IxHash',
          'name' => [ 'Name', 'whatever' ],
          'port' => [ 'Port', '12345' ],
          'secure' => [ 'Secure', 'N' ]
          );
    
    print "Dump of hash\n";
    print Dumper(%portconfig);
    
    print "\nDump of array\n";
    push @portinfo, \%portconfig; 
    print Dumper(@portinfo);
    

    Gives

    C:\demos>perl demo.pl
    Dump of hash
    $VAR1 = 'name';
    $VAR2 = [
              'Name',
              'whatever'
            ];
    $VAR3 = 'port';
    $VAR4 = [
              'Port',
              '12345'
            ];
    $VAR5 = 'secure';
    $VAR6 = [
              'Secure',
              'N'
            ];
    
    Dump of array
    $VAR1 = {
              'name' => [
                          'Name',
                          'whatever'
                        ],
              'port' => [
                          'Port',
                          '12345'
                        ],
              'secure' => [
                            'Secure',
                            'N'
                          ]
            };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create an array of hashes, but I'm having trouble looping through
Trying to create an array or has of ids and names but @campaign_ids_and_names =
i am trying to create array from window.location.hash variable but i am failling. My
Trying to loop through an array of hashes and getting an error message that
I am trying to create an array images to preload by getting each of
I am trying to create an array of hashes, and I am wondering how
I am trying to fill an array of hashes with hashes created through an
I am trying to create an array in jQuery, which is filled through a
I am trying to create an array of around 4 QDataStreams, one for each
Im trying to create an array of tm* structs, and then return them at

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.