|Perl Monk, Perl Meditation|
Re^3: Need to find unique values in hashby davido (Cardinal)
|on Feb 04, 2019 at 18:10 UTC||Need Help??|
There is a Perl module, Module::CoreList that provides a utility called corelist. It can be used to ask Perl the question of whether a module is in the Perl core, and if so, when it got added to Perl's core set of modules. Example:
This means that List::Util has been in the Perl core distribution since Perl 5.7.3. The Perl documentation, "perlhist" can be used to find when a particular version of Perl was introduced.
That's a little cryptic since we're grabbing lines at their textual value, out of context. You could add some more context by using the -C 3 switch on the grep, but we have enough to work with here. What this is telling us is that Perl 5.7.3 was released in March of 2002, and that in July of 2002 it was replaced by Perl 5.8.0. So List::Util has been bundled with a mainline Perl version for over sixteen years.
For what it's worth, corelist Module::CoreList tells us that the Module::CoreList "corelist" utility has also been bundled with Perl for a long time, beginning with Perl 5.8.9, which was released in December of 2008 (over ten years ago).
One should generally not be shy of using modules that are bundled with Perl. We don't give a second thought to putting use strict; and use warnings; at the top of our scripts. Those pragmas are also bundled with the core Perl distribution. If we're hesitant to use List::Util only because we are concerned it won't exist on the target system, we must be concerned that we have such a broken Perl that use warnings may also be suspect.
What is less clear is whether or not List::Util provided uniq contemporarily with the version of Perl that may be installed on your target systems. By reading the Changes file that ships with List::Util we can see that uniq was added in March of 2016, which means the earliest that feature could have gotten into the mainline Perl core would have been Perl 5.24, released in May 2016. But looking at perldoc perl5240delta we see that the version of List::Util bundled with Perl at that time was 1.42, which did not include uniq (added in 1.44). The first mainline Perl version that would have had a version of List::Util greater or equal to 1.44 was Perl 5.26.0 (it bundled List::Util 1.46), released in May 2017. So while it may seem simple to suggest that List::Util has been a part of Perl for so long that it's ancient history, the fact is the feature referred to in this thread was only added to core Perl a little less than two years ago.
However, perlfaq4 has discussed finding unique keys (https://perldoc.perl.org/perlfaq4.html#How-can-I-get-the-unique-keys-from-two-hashes%3f) for as long as I can remember.