http://www.perlmonks.org?node_id=1229364


in reply to Re^2: Need to find unique values in hash
in thread Need to find unique values in hash

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:

$ corelist List::Util Data for 2019-01-20 List::Util was first released with perl v5.7.3

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.

$ perldoc perlhist |grep 5.7.3 5.7.3 2002-Mar-05 5.7.3 3299 85 4295 537 2196 300 2176 626 4171 + 120 t t/**/*(.) (for 1-5.005_56) or **/*.t (for 5.6.0-5.7.3) 5.6.0 5.6.1 5.6.2 5.7.3 Jarkko 5.8.0 2002-Jul-18 1205 31 471 From 5.7 +.3

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.


Dave

Replies are listed 'Best First'.
Re^4: Need to find unique values in hash
by dipit (Sexton) on Feb 05, 2019 at 08:01 UTC

    Really thanks Dave for the information on core modules and their usage.