Array::Diff(3pm)
๐ Array::Diff โ the perl one, bestie ๐
Okay so this is a User Contributed Perl Documentation page for Array::Diff(3pm), and it's genuinely one of the cutest little utility modules out there. It is NOT dramatic. It is NOT complicated. It just diffs two arrays and minds its own business. Let's get into it. ๐ฆ
โจ NAME โจ
Array::Diff โ find the differences between two arrays ๐
๐ธ SYNOPSIS ๐ธ
Look at how tiny this is. Ate.
my @old = ( 'a', 'b', 'c' );
my @new = ( 'b', 'c', 'd' );
my $diff = Array::Diff->diff( \@old, \@new );
$diff->count # 2
$diff->added # [ 'd' ];
$diff->deleted # [ 'a' ];
Likeโฆ 'd' showed up, 'a' left the group chat. That's it, that's the whole vibe. ๐
๐ซถ DESCRIPTION ๐ซถ
So what this module does: it compares two pre-sorted arrays and hands you back the added elements and the deleted elements in two separate arrays. That's the entire job. It's a simple wrapper around Algorithm::Diff, which is doing all the actual heavy lifting behind the scenes โ this module is just the cute front desk. ๐
โ ๏ธ Note, and I need you to actually read this one: the arrays must be sorted before you call diff. If they aren't sorted, bestie, it's giving chaos. Sort first. ๐จ
And if you need more complex array tools, go check out Array::Compare. It's the same energy but with more knobs. ๐
๐ METHODS ๐
new ()
Create a new Array::Diff object. Fresh out the box. Sparkling. โจ
diff ( OLD, NEW )
Compute the differences between two arrays. The results get stored in the added, deleted, and count properties, which you can then peek at using the corresponding methods. ๐
Now here's the fun part โ this method can be called two different ways:
- As an object method โ in which case it will recalculate the differences and repopulate the
count,added, andremovedproperties. (Yes, the docs sayremovedhere. I am reporting faithfully. ๐) - As a static method โ in which case it returns a newly-created
Array::Diffobject with the properties set appropriately. Main character behavior, honestly. ๐
added ( [VALUES ] )
Get or set the elements present in the NEW array and absent in the OLD one, at the comparison performed by the last diff() invocation. These are the new arrivals. The glow-ups. ๐
deleted ( [VALUES] )
Get or set the elements present in the OLD array and absent in the NEW one, at the comparison performed by the last diff() invocation. These are the ones who got quietly removed from the playlist. ๐ญ
count ( [VALUE] )
Get or set the total number of added or deleted elements at the comparison performed by the last diff() invocation. And per the docs: this count should be equal to the sum of the number of elements in the added and deleted properties. Math girlies stay winning. ๐งฎ๐
๐ฅ SEE ALSO ๐ฅ
The whole friend group. All of them:
Array::Compareโ performs the same function as this module, but has options for controlling how it works. More options, more control, still iconic.List::Compareโ similar functionality, but again with more options. The "and another thing" of the family.Algorithm::Diffโ the underlying implementation of the diff algorithm. And heads up: if you've gotAlgorithm::Diff::XSinstalled, that will be used. Faster queen energy only. โญYAML::Diffโ find difference between two YAML documents. (not me โ not me finding YAML diffs)HTML::Differencesโ find difference between two HTML documents. And ngl, this uses a more sane approach thanHTML::Diff. The docs said it, not me. ๐XML::Diffโ find difference between two XML documents.Hash::Diffโ find the differences between two Perl hashes.Data::Diffโ find difference between two arbitrary data structures.Text::Diffโ can find difference between two inputs, which can be data structures or file names.
๐ AUTHOR ๐
Daisuke Murase <typester@cpan.org>
Thank you for your service, king. ๐ซถ
๐ COPYRIGHT AND LICENSE ๐
Copyright (c) 2009 by Daisuke Murase.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. ๐ธ
The full text of the license can be found in the LICENSE file included with this module.
๐ and that's the whole page!! no cap, every single detail is in there, I promise. go diff some arrays, bestie.
โจ Array::Diff(3pm) โ perl v5.36.0, dated 2022-10-16 โจ stay slay, go sort your arrays first ๐ ๐
๐ฆ where this page comes from
- ubuntu noble: libarray-diff-perl 0.09-2 ยท Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libarray-diff-perl 0.09-2 ยท Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libarray-diff-perl 0.09-2 ยท Artistic-1.0-Perl OR GPL-1.0-or-later
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms