I have this associative array in a little Perl program that does something very weird:
#!/usr/bin/perl
use utf8;
use strict;
use warnings;
use open qw(:utf8 :std);
my %distancia = (
esto => 1,
eso => 10,
aquello => 100,
aquí => 1,
ahí => 10,
allí => 100,
);
for my $clave (keys %distancia) {
my $valor = $distancia{$clave};
printf "%-8s es %3d.\n", $clave, $valor;
}
Every time I print it, it randomly changes the order:
mac(tchrist)% perl matriz-asociativa
esto es 1.
aquello es 100.
eso es 10.
allí es 100.
ahí es 10.
aquí es 1.
mac(tchrist)% perl matriz-asociativa
eso es 10.
ahí es 10.
aquí es 1.
esto es 1.
aquello es 100.
allí es 100.
mac(tchrist)% perl matriz-asociativa
allí es 100.
aquí es 1.
ahí es 10.
eso es 10.
esto es 1.
aquello es 100.
mac(tchrist)% perl matriz-asociativa
aquello es 100.
aquí es 1.
allí es 100.
esto es 1.
eso es 10.
ahí es 10.
mac(tchrist)% perl matriz-asociativa
ahí es 10.
aquí es 1.
eso es 10.
aquello es 100.
allí es 100.
esto es 1.
What is happening to me here, and what should I do to get a certain order every time?
If it matters, it says that the version of perl I have is v5.22.0 :
mac(tchrist)% perl -v
This is perl 5, version 22, subversion 0 (v5.22.0) built for darwin-2level
Copyright 1987-2015, Larry Wall
Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.
Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl". If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.