caballerosteam / sort-naturally-xs Goto Github PK
View Code? Open in Web Editor NEWPerl natural sorting module
Perl natural sorting module
See http://matrix.cpantesters.org/?dist=Sort-Naturally-XS%200.7.9;os=linux;reports=1 for a list of fail reports --- it seems that all of the current linux fail reports are locale-related. Sorry, I don't have more information why it fails on some of my smokers.
Hi! Thank you for writing Sort::Naturally::XS, it looks really great.
I'm having trouble using it though because right now it die()s whenever it tries to sort strings with UTF-8 characters. Here's the simplest example I could come up with to reproduce it:
perl -MSort::Naturally::XS -E 'my @l = ( qq(\x{2603}), q(abc) ); say join q(, ) => nsort(@l)'
Wide character in subroutine entry at -e line 1.
Ideally, Sort::Naturally::XS would use the Unicode Collation Algorithm to compare unicode characters/strings, but even just giving it some sort of fixed sort value (instead of raising an exception) and documenting this should be enough I guess.
Hope this helps! And thanks again for writing and maintaining Sort::Naturally::XS!
Hi! First of all, let me thank you again for writing and maintaining Sort::Naturally::XS. I've been making some tests with it and it looks like it really speed things up!
The issue here is with the return value of nsort. Whenever it gets an empty list, instead of returning another empty list (e.g. ()
) it is returning undef
, which behaves as a single element when in list context. This is a very common issue with list/scalar context!
perl -MSort::Naturally::XS -E 'my @l; say scalar @l; my @o = nsort(@l); say scalar @o'
0
1
So if I do (a common case, I suspect):
@list = nsort( @list );
and @list
is empty (e.g ()
), then after the call to nsort
it will not be empty anymore, and instead contain 1 element: (undef)
. In fact:
> perl -Ilib -MSort::Naturally::XS -E 'my @l; @l = nsort(@l); use DDP; p @l'
[
[0] undef
]
The solution is returning the empty list ()
, which in scalar context is undef
and in list context is, well, an actual empty list :)
Hope this helps! Thanks again for writing such an interesting module!
This would make the repository easy to find from MetaCPAN. Please see https://perlmaven.com/how-to-add-link-to-version-control-system-of-a-cpan-distributions
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.