Giter Club home page Giter Club logo

Comments (4)

abraxxa avatar abraxxa commented on June 1, 2024

Just as I expected, one var has the UTF8 flag set and one doesn't:

CHECKING port
	x: '10022'
SV = PV(0x564789fbea70) at 0x564789fc3778
  REFCNT = 2
  FLAGS = (POK,pPOK)
  PV = 0x564789fc4de0 "10022"\0
  CUR = 5
  LEN = 10
	y: '10022'
SV = PV(0x564789ffa9e0) at 0x56478a015490
  REFCNT = 2
  FLAGS = (POK,pPOK,UTF8)
  PV = 0x564789ff4890 "10022"\0 [UTF8 "10022"]
  CUR = 5
  LEN = 10
DIFFERENT! x: 10022, y: 10022

I added a failing test case in my fork.

The big question is: should strings with different encoding but identical characters handled as diff or not?

from struct-diff.pm.

mr-mixas avatar mr-mixas commented on June 1, 2024

Hi,

I think diff() behave correctly, data is different after all.

If you need no diff in this case, just redefine freezer and drop (or set) utf flag for scalars in it, see https://github.com/mr-mixas/Struct-Diff.pm#configuration-variables

from struct-diff.pm.

abraxxa avatar abraxxa commented on June 1, 2024

That's almost exactly what I did after I found out what the difference is. My custom freezer just returns scalars as such without invoking Storable which results in string comparison.

I'm still wondering what this line is supposed to do? https://metacpan.org/release/Struct-Diff/source/lib/Struct/Diff.pm#L252

I'd suggest adding my tests but changing the ascii vs. utf8 test to pass when different as this tells someone like me what (s)he should expect from the module and add documentation for it.

Comparing scalars, whether they are strings or numbers, as their internal representation is not what most if not all Perl 5 developers would expect. Maybe you should think about a config option for the module which you might want to change with the next major version bump (1.0).

from struct-diff.pm.

mr-mixas avatar mr-mixas commented on June 1, 2024

I'd suggest adding my tests but changing the ascii vs. utf8 test to pass when different as this tells someone like me what (s)he should expect from the module and add documentation for it.

Good thought, could you make a PR?

I'm still wondering what this line is supposed to do? https://metacpan.org/release/Struct-Diff/source/lib/Struct/Diff.pm#L252

Literally: refs compared by addresses, all the rest by value using freezer.

Comparing scalars, whether they are strings or numbers, as their internal representation is not what most if not all Perl 5 developers would expect.

Within the scope of perl it is. But when it comes to operations with systems written in other languages this become critical. Struct::Diff do it best to provide maximum accuracy, which can bee loosen when needed (this case, presicion for floats, '0' vs 0 and so on). I think I should add this to docs =)

from struct-diff.pm.

Related Issues (1)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.