3 ms·
Perl has done per-run randomization of the iteration order as well for a while (more than a decade). % repeat 5 perl -e '%h=(a => 1, b => 2, c=> 3); print
by jsnell 2y ago
Perl has done per-run randomization of the iteration order as well for a while (more than a decade).
% repeat 5 perl -e '%h=(a => 1, b => 2, c=> 3); print for keys %h; print "\n"'
bca
cba
bac
bac
bac
- h4ck_th3_pl4n3t 2y ago[flagged]
- vessenes 2y agoCounterpoint - Perl 5 should be (and frankly probably is) required reading for all language designers. You may not like its opinionated point of view, but it glued together the early internet, and occupied a niche so large for so long that calling it a niche is underselling it. Misunderstanding why Perl worked, and what worked about it is a miss in an any serious software engineer’s education.
- Dylan16807 2y agoNotice how almost all of those are just a variable name or a number on a line by itself. Those being valid programs says very little about Perl as a language. A few semicolons being okay in a mix with the above doesn't say much either, and the couple gnarliest examples happened to hit #, the comment character, so the rest isn't even being treated as code.
- okwhateverdude 2y agoCute story on why that came to be. At Booking.com, a degenerate case that lead to a DoS that you could cause with specially crafted URLs (I think, memory is a bit foggy) spurned Yves Orton to do that hacking. And it broke a lot of code where the ordering had been consistent enough that people relied on it.
- darrenf 2y agoWay longer than a decade. You can see it in the perlfunc man page way back in 1996[0]. Of the same vintage is `Tie::IxHash`, which retains insertion order % repeat 5 perl -MTie::IxHash -E 'tie my %foo, "Tie::IxHash"; @foo{qw{ c a b }} = (1)x3; printf("%s%s%s\n",keys %foo)' cab cab cab cab cab [0] https://metacpan.org/release/NI-S/perl5.003_02a/view/pod/perlfunc.pod#keys-ASSOC_ARRAY https://metacpan.org/release/NI-S/perl5.003_02a/view/pod/per...
- rurban 2y agoNo, Yves added randomization per iteration as described in the parent. Before it was only dependent on the per-process seed. So the seed could be computed given enough attempts to iter a hash (eg a public JSON API)
- darrenf 2y agoBut the parent is invoking `perl` itself 5 times, rather than iterating 5 times within one process.