--- layout: docs permalink: /docs/stable-outputs/ title: 'Stable order for outputs' --- Data structures such as [Perl hashes](http://perldoc.perl.org/functions/keys.html), [Python dictionaries](https://docs.python.org/library/stdtypes.html#mapping-types-dict) and [sets](https://docs.python.org/library/stdtypes.html#set-types-set-frozenset), or [Ruby Hash objects](https://ruby-doc.org/core/Hash.html) will list their keys in a different order on every run to limit [algorithmic complexity attacks](http://perldoc.perl.org/perlsec.html#Algorithmic-Complexity-Attacks). Perl ---- The following Perl code will output the list in a different order on every run:
{% highlight perl %} foreach my $package (keys %deps) { print MANIFEST, "$package: $deps[$packages]"; } {% endhighlight %}
To get a deterministic output, the easiest way is to explicitly sort the keys:
{% highlight perl %} foreach my $package (sort keys %deps) { print MANIFEST, "$package: $deps[$packages]"; } {% endhighlight %}
For Perl, it is possible to set `PERL_HASH_SEED=0` in the environment. This will result in hash keys always being in the same order. See [perlrun(1)](http://perldoc.perl.org/perlrun.html) for more information. Python ------ Python users can similarly set the environment variable [PYTHONHASHSEED](https://docs.python.org/using/cmdline.html#envvar-PYTHONHASHSEED). When set to a given integer value, orders in dictionaries and sets will be the same on every run. General ------- Beware that the [locale settings]({{ "/docs/locales/" | relative_url }}) might affect the output of some sorting functions or the `sort` command.