Compare(3pm)

πŸ“¦
version 1.0.1 Β· 2 versions
  • 1.0.1 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 1.0.1 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– Compare(3pm) β€” the manual page bestie πŸ’–

okay so you found the Compare(3pm) page, part of the User Contributed Perl Documentation, and honestly? slay. it's the Struct::Compare module and it's about to make your whole life easier, no cap.


✨ NAME ✨

Struct::Compare β€” Recursive diff for perl structures. literally what it says on the tin, bestie. 🫢


🌸 SYNOPSIS 🌸

use Struct::Compare;
my $is_different = compare($ref1, $ref2);

that's it. that's the whole vibe. two refs in, a truthy/falsey answer out. πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

so here's the tea: compare takes two values of any type and structure and returns true if they're the same. and when I say any, I mean it β€” it does a deep comparison of the structures, so a hash of a hash of a whatever will be compared correctly. like it will go all the way down. it does not get tired. it does not give up. it is that girl. πŸ‘‘

and why do you care? because this is especially useful for writing unit tests for your modules! yes bestie, your test suite is about to eat. πŸ“


⭐ PUBLIC FUNCTIONS ⭐

  • $bool = compare($var1, $var2) β€” recursively compares $var1 to $var2, returning false if either structure is different than the other at any point. and here's a lil detail that's lowkey important: if both are undefined, it returns true as well, because that is considered equal. two undefs = a match made in heaven, iykyk. πŸ’œ

πŸ’€ BUGS/NEEDED ENHANCEMENTS πŸ’€

  • blessed references β€” okay so compare currently does not deal with blessed references. ngl, the author needs to look into how to deal with this. so if your structures are full of blessed objects, this is your heads-up: it's giving "known limitation", not "it just works". πŸ™ˆ

πŸŽ€ LICENSE πŸŽ€

(The MIT License)

Copyright (c) 2001 Ryan Davis, Zen Spider Software

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

like yes, it's a wall of legal text, but it's iconic legal text and every single word of it matters. read it, don't skip it, periodt. ✨


🌈 AUTHOR 🌈

Ryan Davis <ryand-cmp@zenspider.com> Zen Spider Software <http://www.zenspider.com/ZSS/>


and that's the whole page bestie!! this one was written by Ryan Davis of Zen Spider Software, and this copy is from perl v5.36.0, dated 2022-12-04. go forth and diff your structures, you absolute main character. πŸ’…πŸ«Ά

πŸ“¦ where this page comes from