Sort-Fields-1.003/0000755000076500000240000000000014777254774012656 5ustar brianstaffSort-Fields-1.003/LICENSE0000644000076500000240000002166614777254773013675 0ustar brianstaffThe Sort::Fields module is licensed under the Artistic License 2.0. Artistic License 2.0 Copyright (c) 2000-2006, The Perl Foundation. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble ******** This license establishes the terms under which a given free software Package may be copied, modified, distributed, and/or redistributed. The intent is that the Copyright Holder maintains some artistic control over the development of that Package while still keeping the Package available as open source and free software. You are always permitted to make arrangements wholly outside of this license directly with the Copyright Holder of a given Package. If the terms of this license do not permit the full use that you propose to make of the Package, you should contact the Copyright Holder and seek a different licensing arrangement. Definitions *********** "Copyright Holder" means the individual(s) or organization(s) named in the copyright notice for the entire Package. "Contributor" means any party that has contributed code or other material to the Package, in accordance with the Copyright Holder's procedures. "You" and "your" means any person who would like to copy, distribute, or modify the Package. "Package" means the collection of files distributed by the Copyright Holder, and derivatives of that collection and/or of those files. A given Package may consist of either the Standard Version, or a Modified Version. "Distribute" means providing a copy of the Package or making it accessible to anyone else, or in the case of a company or organization, to others outside of your company or organization. "Distributor Fee" means any fee that you charge for Distributing this Package or providing support for this Package to another party. It does not mean licensing fees. "Standard Version" refers to the Package if it has not been modified, or has been modified only in ways explicitly requested by the Copyright Holder. "Modified Version" means the Package, if it has been changed, and such changes were not explicitly requested by the Copyright Holder. "Original License" means this Artistic License as Distributed with the Standard Version of the Package, in its current version or as it may be modified by The Perl Foundation in the future. "Source" form means the source code, documentation source, and configuration files for the Package. "Compiled" form means the compiled bytecode, object code, binary, or any other form resulting from mechanical transformation or translation of the Source form. Permission for Use and Modification Without Distribution ******************************************************** (1) You are permitted to use the Standard Version and create and use Modified Versions for any purpose without restriction, provided that you do not Distribute the Modified Version. Permissions for Redistribution of the Standard Version ****************************************************** (2) You may Distribute verbatim copies of the Source form of the Standard Version of this Package in any medium without restriction, either gratis or for a Distributor Fee, provided that you duplicate all of the original copyright notices and associated disclaimers. At your discretion, such verbatim copies may or may not include a Compiled form of the Package. (3) You may apply any bug fixes, portability changes, and other modifications made available from the Copyright Holder. The resulting Package will still be considered the Standard Version, and as such will be subject to the Original License. Distribution of Modified Versions of the Package as Source ********************************************************** (4) You may Distribute your Modified Version as Source (either gratis or for a Distributor Fee, and with or without a Compiled form of the Modified Version) provided that you clearly document how it differs from the Standard Version, including, but not limited to, documenting any non-standard features, executables, or modules, and provided that you do at least ONE of the following: (a) make the Modified Version available to the Copyright Holder of the Standard Version, under the Original License, so that the Copyright Holder may include your modifications in the Standard Version. (b) ensure that installation of your Modified Version does not prevent the user installing or running the Standard Version. In addition, the Modified Version must bear a name that is different from the name of the Standard Version. (c) allow anyone who receives a copy of the Modified Version to make the Source form of the Modified Version available to others under (i) the Original License or (ii) a license that permits the licensee to freely copy, modify and redistribute the Modified Version using the same licensing terms that apply to the copy that the licensee received, and requires that the Source form of the Modified Version, and of any works derived from it, be made freely available in that license fees are prohibited but Distributor Fees are allowed. Distribution of Compiled Forms of the Standard Version or Modified ****************************************************************** Versions without the Source *************************** (5) You may Distribute Compiled forms of the Standard Version without the Source, provided that you include complete instructions on how to get the Source of the Standard Version. Such instructions must be valid at the time of your distribution. If these instructions, at any time while you are carrying out such distribution, become invalid, you must provide new instructions on demand or cease further distribution. If you provide valid instructions or cease distribution within thirty days after you become aware that the instructions are invalid, then you do not forfeit any of your rights under this license. (6) You may Distribute a Modified Version in Compiled form without the Source, provided that you comply with Section 4 with respect to the Source of the Modified Version. Aggregating or Linking the Package ********************************** (7) You may aggregate the Package (either the Standard Version or Modified Version) with other packages and Distribute the resulting aggregation provided that you do not charge a licensing fee for the Package. Distributor Fees are permitted, and licensing fees for other components in the aggregation are permitted. The terms of this license apply to the use and Distribution of the Standard or Modified Versions as included in the aggregation. (8) You are permitted to link Modified and Standard Versions with other works, to embed the Package in a larger work of your own, or to build stand-alone binary or bytecode versions of applications that include the Package, and Distribute the result without restriction, provided the result does not expose a direct interface to the Package. Items That are Not Considered Part of a Modified Version ******************************************************** (9) Works (including, but not limited to, modules and scripts) that merely extend or make use of the Package, do not, by themselves, cause the Package to be a Modified Version. In addition, such works are not considered parts of the Package itself, and are not subject to the terms of this license. General Provisions ****************** (10) Any use, modification, and distribution of the Standard or Modified Versions is governed by this Artistic License. By using, modifying or distributing the Package, you accept this license. Do not use, modify, or distribute the Package, if you do not accept this license. (11) If your Modified Version has been derived from a Modified Version made by someone other than you, you are nevertheless required to ensure that your Modified Version complies with the requirements of this license. (12) This license does not grant you the right to use any trademark, service mark, tradename, or logo of the Copyright Holder. (13) This license includes the non-exclusive, worldwide, free-of-charge patent license to make, have made, use, offer to sell, sell, import and otherwise transfer the Package with respect to any patent claims licensable by the Copyright Holder that are necessarily infringed by the Package. If you institute patent litigation (including a cross-claim or counterclaim) against any party alleging that the Package constitutes direct or contributory patent infringement, then this Artistic License to you shall terminate on the date that such litigation is filed. (14) Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Sort-Fields-1.003/Changes0000644000076500000240000000157714777254773014162 0ustar brianstaffRevision history for Perl extension Sort::Fields 1.003 2025-04-14T18:54:51Z * require a newer version.pm for v5.10.1 tests 1.002 2025-01-27T12:38:26Z * refresh distro and move to BRIANDFOY 1.001 2021-01-04T23:52:23Z * rt.cpan.org will shut down in March 2021, so it's a good time to give this module different meta data * brian d foy is maintaining the distro, but this is limited to making it work with current services. The code is all Joseph Hall's. No future development or features is planned * The test.pl is moved, with slight modifications, to t/test.t and Test::More * If you experience problems, report them in GitHub: https://github.com/briandfoy/sort-fields * If you'd like to take over the module, open an issue. 0.90 - 1998-01-30 * first reasonable beta version * incorporates a stable sorting option 0.01 - 1998-01-24 * original version; created by h2xs 1.16 Sort-Fields-1.003/MANIFEST0000644000076500000240000000051514777254774014010 0ustar brianstaffChanges INSTALL.SKIP lib/Sort/Fields.pm LICENSE Makefile.PL MANIFEST This list of files MANIFEST.SKIP README.pod SECURITY.md t/test.t t/test_manifest xt/changes.t META.yml Module YAML meta-data (added by MakeMaker) META.json Module JSON meta-data (added by MakeMaker) Sort-Fields-1.003/t/0000755000076500000240000000000014777254774013121 5ustar brianstaffSort-Fields-1.003/t/test.t0000644000076500000240000001145714777254773014274 0ustar brianstaffuse utf8; use strict; use warnings; use Test::More 0.94; BEGIN { use_ok( 'Sort::Fields' ) } #################################################################### # test warnings, errors sub test_msg { my( $code, $warn_expected, $die_expected ) = @_; my ($warn, $die) = ('', ''); local $SIG{__WARN__} = sub { $warn = shift }; local $SIG{__DIE__} = sub { $die = shift }; eval $code; $warn =~ s/ at (?!.*\bat\b)[\w\W]*$//; $die =~ s/ at (?!.*\bat\b)[\w\W]*$//; subtest $code => sub { is( $warn, $warn_expected, "warn message is correct" ) or diag( "code: $code\nwarn: $warn\n" ); is( $die, $die_expected, "die message is correct" ) or diag( "code: $code\nwarn: $die\n" ); }; } # warnings change from version to version, so let this perl # tell you what it is now. my $regex_warning = do { eval "m/(/"; my $die = $@; $die =~ s/ at (?!.*\bat\b)[\w\W]*$//; $die; }; #diag( "regex warning is $regex_warning" ); foreach ( qw(fieldsort stable_fieldsort make_fieldsort make_stable_fieldsort) ) { test_msg qq{ $_(); }, "", "$_ requires argument(s)"; test_msg qq{ $_(1); }, "", "$_ field specifiers must be in anon array"; test_msg qq{ $_([]); }, "", "$_ must have at least one field specifier"; test_msg qq{ $_(['x']); }, "", "improperly formatted $_ column specifier 'x'"; test_msg qq{ $_(q/(/, ['1n']); }, "", "probable regexp error in $_ arg: /(/\n$regex_warning"; } foreach ( qw(fieldsort stable_fieldsort) ) { local $^W = 1; # This is definitely old school, # but this is part of the condition to trigger the message test_msg qq{ scalar $_([1], qw(a b c)); }, "fieldsort called in scalar or void context", ""; } #################################################################### # test that it all works my @data = ; is_deeply( [fieldsort(['1n'], @data)], [map {$_->[0]} sort {$a->[1]<=>$b->[1]} map {[$_, split /\s+/]} @data], "ascending numeric" ); is_deeply( [fieldsort([2], @data)], [map {$_->[0]} sort {$a->[2]cmp$b->[2]} map {[$_, split /\s+/]} @data], "ascending alpha" ); is_deeply( [fieldsort(['3n'], @data)], [map {$_->[0]} sort {$a->[3]<=>$b->[3]} map {[$_, split /\s+/]} @data], "ascending numeric" ); is_deeply( [fieldsort(['4n'], @data)], [map {$_->[0]} sort {$a->[4]<=>$b->[4]} map {[$_, split /\s+/]} @data], "ascending numeric" ); is_deeply( [fieldsort(['-1n'], @data)], [map {$_->[0]} sort {$b->[1]<=>$a->[1]} map {[$_, split /\s+/]} @data], "descending numeric" ); is_deeply( [fieldsort([-2], @data)], [map {$_->[0]} sort {$b->[2]cmp$a->[2]} map {[$_, split /\s+/]} @data], "descending alpha" ); is_deeply( [fieldsort(['-3n'], @data)], [map {$_->[0]} sort {$b->[3]<=>$a->[3]} map {[$_, split /\s+/]} @data], "descending numeric" ); is_deeply( [fieldsort(['-4n'], @data)], [map {$_->[0]} sort {$b->[4]<=>$a->[4]} map {[$_, split /\s+/]} @data], "descending numeric" ); is_deeply( [fieldsort([1, '4n'], @data)], [map {$_->[0]} sort {$a->[1]cmp$b->[1] or $a->[4]<=>$b->[4]} map {[$_, split /\s+/]} @data], "ascending alpha, then ascending numeric" ); is_deeply( [fieldsort([1, '-4n'], @data)], [map {$_->[0]} sort {$a->[1]cmp$b->[1] or $b->[4]<=>$a->[4]} map {[$_, split /\s+/]} @data], "ascending alpha, then descending numeric" ); is_deeply( [fieldsort([2, 0], @data)], [map {$_->[0]} sort {$a->[2]cmp$b->[2] or $a->[0]cmp$b->[0]} map {[$_, split /\s+/]} @data], "ascending alpha, then ascending alpha" ); is_deeply( [fieldsort([2, '-0'], @data)], [map {$_->[0]} sort {$a->[2]cmp$b->[2] or $b->[0]cmp$a->[0]} map {[$_, split /\s+/]} @data], "ascending alpha, then descending numeric" ); { my $i = 0; is_deeply( [fieldsort(['-', '1n'], @data)], [map {$_->[0]} sort {$a->[2]<=>$b->[2] or $a->[1]<=>$b->[1]} map {[$_, $i++, split /\s+/]} @data], "stable, ascending numeric" ); } { my $i = 0; is_deeply( [stable_fieldsort(['1n'], @data)], [map {$_->[0]} sort {$a->[2]<=>$b->[2] or $a->[1]<=>$b->[1]} map {[$_, $i++, split /\s+/]} @data], "stable, ascending numeric" ); } { my $i = 0; is_deeply( [stable_fieldsort(['1n', -2], @data)], [map {$_->[0]} sort {$a->[2]<=>$b->[2] or $b->[3]cmp$a->[3] or $a->[1]<=>$b->[1]} map {[$_, $i++, split /\s+/]} @data], "stable, ascending numeric, then descending alphabetic" ); } done_testing(); __END__ 0 a 1 -4.5 0 a 2 -2.5 0 b 3 1e2 1 b 4 123456 1 b 5 1e3 1 b 6 2e5 0 b 7 .00001 0 a 8 .00002 1 a 9 -.234e2 1 b 10 1e-1 0 a 12 1e-2 0 a 13 .123 0 a 14 .234 0 b 15 1.234 0 a 16 12345.6789 1 a 17 12345.6788 1 a 18 12345.6787 1 a 19 -2222 0 b 20 -2223 0 b 21 -1e1 1 b 22 -1e-1 1 b 23 -2e2 0 b 24 -2e-2 0 b 25 -3e3 0 b 26 -3e-3 0 b 27 123345.123234 0 a 28 123345.123235 0 a 29 123345.123233 0 a 30 -4.6 0 b 31 -4.7 0 b 32 -4.8 1 b 33 -4.5e1 1 a 34 1.23 1 a 35 2.345 1 b 36 345.456 1 a 37 45678.67567 0 b 38 23423422.34234234 1 a 39 123124123 Sort-Fields-1.003/t/test_manifest0000644000076500000240000000000714777254773015705 0ustar brianstafftest.t Sort-Fields-1.003/xt/0000755000076500000240000000000014777254774013311 5ustar brianstaffSort-Fields-1.003/xt/changes.t0000644000076500000240000000020314777254773015100 0ustar brianstaffuse Test::More; eval 'use Test::CPAN::Changes'; plan skip_all => 'Test::CPAN::Changes required for this test' if $@; changes_ok(); Sort-Fields-1.003/README.pod0000644000076500000240000001160514777254773014321 0ustar brianstaff=pod =encoding utf8 =for HTML =for HTML =for HTML =for HTML =for HTML Coverage Status =for HTML =for HTML =head1 The Sort::Fields module This is the I for the L Perl module. You're probably looking at this because you don't know where else to find what you're looking for. Read this once and you might never have to read one again for any Perl module. Joseph Hall wrote this module decades ago and it's basically on life support to make it fit in with modern packaging. The code is still what Joseph created, and no new development is intended. =head2 Documentation To read about L, look at the embedded documentation in the module itself. Inside the distribution, you can format it with L: % perldoc lib/Sort/Fields.pm If you have already installed the module, you can specify the module name instead of the file location: % perldoc Sort::Fields You can read the documentation and inspect the meta data at L. The standard module documentation has example uses in the SYNOPSIS section, but you can also look in the I directory (if it's there), or look at the test files in I. =head2 Installation You can install this module with a CPAN client, which will resolve and install the dependencies: % cpan Sort::Fields % cpanm Sort::Fields You can also install directly from the distribution directory, which will also install the dependencies: % cpan . % cpanm . You could install just this module manually: % perl Makefile.PL % make % make test % make install You probably don't want to do that unless you're fiddling with the module and only want to run the tests without installing anything. =head2 Source location The meta data, such as the source repository and bug tracker, is in I or the I files it creates. You can find that on those CPAN web interfaces, but you can also look at files directly in the source repository: L If you find a problem, file a ticket in the L. There are also backup repositories hosted on other services. These reflect the state of the main repo and exist only for redundancy: =over 4 =item * L =item * L =item * L =back =head2 GitHub Attestations This distribution now uses L, which allow you to verify that the archive file you have was made from the official repo. You need a GitHub account and the L. # download the distro file from GitHub, MetaCPAN, or a CPAN mirror $ gh auth login ...follow instructions... $ gh attestation verify Sort-Fields-1.23.tar.gz --owner briandfoy =head2 Getting help Although I'm happy to hear from module users in private email, that's the best way for me to forget to do something. Besides the issue trackers, you can find help at L or L, both of which have many competent Perlers who can answer your question, almost in real time. They might not know the particulars of this module, but they can help you diagnose your problem. You might like to read L. =head2 Copyright and License You should have received a I file, but the license is also noted in the module files. About the only thing you can't do is pretend that you wrote code that you didn't. =head2 Good luck! Enjoy, brian d foy, briandfoy@pobox.com =cut Sort-Fields-1.003/MANIFEST.SKIP0000644000076500000240000000212014777254773014546 0ustar brianstaff #!start included /usr/local/perls/perl-5.20.0/lib/5.20.0/ExtUtils/MANIFEST.SKIP # Avoid version control files. \bRCS\b \bCVS\b \bSCCS\b ,v$ \B\.svn\b \B\.git\b \B\.gitignore\b \b_darcs\b \B\.cvsignore$ # Avoid VMS specific MakeMaker generated files \bDescrip.MMS$ \bDESCRIP.MMS$ \bdescrip.mms$ # Avoid Makemaker generated and utility files. \bMANIFEST\.bak \bMakefile$ \bblib/ \bMakeMaker-\d \bpm_to_blib\.ts$ \bpm_to_blib$ \bblibdirs\.ts$ # 6.18 through 6.25 generated this # Avoid Module::Build generated and utility files. \bBuild$ \b_build/ \bBuild.bat$ \bBuild.COM$ \bBUILD.COM$ \bbuild.com$ # Avoid temp and backup files. ~$ \.old$ \#$ \b\.# \.bak$ \.tmp$ \.# \.rej$ # Avoid OS-specific files/dirs # Mac OSX metadata \B\.DS_Store # Mac OSX SMB mount metadata files \B\._ # Avoid Devel::Cover and Devel::CoverX::Covered files. \bcover_db\b \bcovered\b # Avoid MYMETA files ^MYMETA\. #!end included /usr/local/perls/perl-5.20.0/lib/5.20.0/ExtUtils/MANIFEST.SKIP \.?appveyor.yml \.releaserc \.lwpcookies \.github \bMANIFEST\s\d \bChanges\s\d \.icloud$ \A\.github\b \.gitattributes\b Sort-Fields-1.003/META.yml0000664000076500000240000000141714777254774014134 0ustar brianstaff--- abstract: 'Sort lines containing delimited fields' author: - 'Joseph N. Hall ' build_requires: Test::More: '1' version: '0.86' configure_requires: ExtUtils::MakeMaker: '6.64' File::Spec::Functions: '0' dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 7.70, CPAN::Meta::Converter version 2.150010' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Sort-Fields no_index: directory: - t - inc requires: perl: '5.008' resources: bugtracker: https://github.com/briandfoy/sort-fields/issues homepage: https://github.com/briandfoy/sort-fields repository: https://github.com/briandfoy/sort-fields version: '1.003' x_serialization_backend: 'CPAN::Meta::YAML version 0.018' Sort-Fields-1.003/lib/0000755000076500000240000000000014777254774013424 5ustar brianstaffSort-Fields-1.003/lib/Sort/0000755000076500000240000000000014777254774014353 5ustar brianstaffSort-Fields-1.003/lib/Sort/Fields.pm0000644000076500000240000002262114777254773016121 0ustar brianstaffpackage Sort::Fields; use strict; use vars qw($VERSION @EXPORT); use Exporter qw(import); require 5.003_03; ; # Items to export into callers namespace by default. Note: do not export # names by default without a very good reason. Use EXPORT_OK instead. # Do not simply export all your public functions/methods/constants. @EXPORT = qw( make_fieldsort fieldsort make_stable_fieldsort stable_fieldsort ); $VERSION = '1.003'; use Carp; sub make_fieldsort { my $selfname; if ((caller)[0] eq 'Sort::Fields') { ($selfname) = (caller 1)[3] =~ /([^:]*)$/; } else { $selfname = 'make_fieldsort' }; unless (@_) { croak "$selfname requires argument(s)"; } my ($sep, $cols); if (ref $_[0]) { $sep = '\\s+' } else { $sep = shift; } unless (ref($cols = shift) eq 'ARRAY') { croak "$selfname field specifiers must be in anon array"; } my (@sortcode, @col); my $level = 1; my $maxcol = -1; my $stable = 0; if (@$cols and $$cols[0] eq '-') { shift @$cols; $stable = 1; } unless (@$cols) { croak "$selfname must have at least one field specifier"; } for (@$cols) { unless (/^-?\d+n?$/) { croak "improperly formatted $selfname column specifier '$_'"; } my ($a, $b) = /^-/ ? qw(b a) : qw(a b); my $op = /n$/ ? '<=>' : 'cmp'; my ($col) = /^-?(\d+)/; if ($col == 0) { # column 0 gives the entire string push @sortcode, "\$${a}->[0] $op \$${b}->[0]"; next; } push @col, (/(\d+)/)[0] - 1; $maxcol = $col[-1] if $maxcol < $col[-1]; if ($stable) { # indices are offset by 1 in this case my $levp1 = $level + 1; push @sortcode, "\$${a}->[$levp1] $op \$${b}->[$levp1]"; } else { push @sortcode, "\$${a}->[$level] $op \$${b}->[$level]"; } $level++; } # have to check this all by itself, since if there's a regex # error it won't show up until the sub is called (urk!) eval '"" =~ /$sep/'; if ($@) { croak "probable regexp error in $selfname arg: /$sep/\n$@"; } my $splitfunc; $splitfunc = eval 'sub { (split /$sep/o, $_, $maxcol + 2)[@col] } '; if ($@) { die "eval failed in $selfname (internal error?)\n$@"; } my $sortcode = join " or ", @sortcode; my $sub; if ($stable) { my $i; # the $i for the stable sort closure $sub = eval qq{ sub { if (\$^W and not wantarray) { carp "fieldsort called in scalar or void context"; } \$i = 0; # reset counter in case reusing this closure map \$_->[0], sort { $sortcode or \$a->[1] <=> \$b->[1] } map [\$_, \$i++, \$splitfunc->(\$_)], \@_; } } } else { $sub = eval qq{ sub { if (\$^W and not wantarray) { carp "fieldsort called in scalar or void context"; } map \$_->[0], sort { $sortcode } map [\$_, \$splitfunc->(\$_)], \@_; } } } if ($@) { die "eval failed in $selfname (internal error?)\n$@"; } $sub; } sub make_stable_fieldsort { unless (@_) { croak "make_stable_fieldsort requires argument(s)"; } if (ref $_[0] eq 'ARRAY') { unshift @{$_[0]}, '-'; } elsif (@_ > 1 and ref $_[1] eq 'ARRAY') { unshift @{$_[1]}, '-'; } make_fieldsort @_; } sub fieldsort { unless (@_) { croak "fieldsort requires argument(s)"; } my ($sep, $cols); if (ref $_[0]) { $sep = '\\s+' } else { $sep = shift; } $cols = shift; make_fieldsort($sep, $cols)->(@_); } sub stable_fieldsort { unless (@_) { croak "stable_fieldsort requires argument(s)"; } my ($sep, $cols); if (ref $_[0] eq 'ARRAY') { $sep = '\\s+'; unshift @{$_[0]}, '-'; } elsif (@_ > 1 and ref $_[1] eq 'ARRAY') { $sep = shift; unshift @{$_[1]}, '-'; } $cols = shift; make_fieldsort($sep, $cols)->(@_); } 1; __END__ =encoding utf8 =head1 NAME Sort::Fields - Sort lines containing delimited fields =head1 SYNOPSIS use Sort::Fields; @sorted = fieldsort [3, '2n'], @lines; @sorted = fieldsort '\+', [-1, -3, 0], @lines; $sort_3_2n = make_fieldsort [3, '2n'], @lines; @sorted = $sort_3_2n->(@lines); =head1 DESCRIPTION Sort::Fields provides a general purpose technique for efficiently sorting lists of lines that contain data separated into fields. Sort::Fields automatically imports two subroutines, C and C, and two variants, C and C. C generates a sorting subroutine and returns a reference to it. C is a wrapper for the C subroutine. The first argument to make_fieldsort is a delimiter string, which is used as a regular expression argument for a C operator. The delimiter string is optional. If it is not supplied, make_fieldsort splits each line using C. The second argument is an array reference containing one or more field specifiers. The specifiers indicate what fields in the strings will be used to sort the data. The specifier "1" indicates the first field, "2" indicates the second, and so on. A negative specifier like "-2" means to sort on the second field in reverse (descending) order. To indicate a numeric rather than alphabetic comparison, append "n" to the specifier. A specifier of "0" means the entire string ("-0" means the entire string, in reverse order). The order in which the specifiers appear is the order in which they will be used to sort the data. The primary key is first, the secondary key is second, and so on. C is roughly equivalent to C(@data)>. Avoid calling fieldsort repeatedly with the same sort specifiers. If you need to use a particular sort more than once, it is more efficient to call C once and reuse the subroutine it returns. C and C are like their "unstable" counterparts, except that the items that compare the same are maintained in their original order. =head1 EXAMPLES Some sample data (in array C<@data>): 123 asd 1.22 asdd 32 ewq 2.32 asdd 43 rewq 2.12 ewet 51 erwt 34.2 ewet 23 erww 4.21 ewet 91 fdgs 3.43 ewet 123 refs 3.22 asdd 123 refs 4.32 asdd # alpha sort on column 1 print fieldsort [1], @data; 123 asd 1.22 asdd 123 refs 3.22 asdd 123 refs 4.32 asdd 23 erww 4.21 ewet 32 ewq 2.32 asdd 43 rewq 2.12 ewet 51 erwt 34.2 ewet 91 fdgs 3.43 ewet # numeric sort on column 1 print fieldsort ['1n'], @data; 23 erww 4.21 ewet 32 ewq 2.32 asdd 43 rewq 2.12 ewet 51 erwt 34.2 ewet 91 fdgs 3.43 ewet 123 asd 1.22 asdd 123 refs 3.22 asdd 123 refs 4.32 asdd # reverse numeric sort on column 1 print fieldsort ['-1n'], @data; 123 asd 1.22 asdd 123 refs 3.22 asdd 123 refs 4.32 asdd 91 fdgs 3.43 ewet 51 erwt 34.2 ewet 43 rewq 2.12 ewet 32 ewq 2.32 asdd 23 erww 4.21 ewet # alpha sort on column 2, then alpha on entire line print fieldsort [2, 0], @data; 123 asd 1.22 asdd 51 erwt 34.2 ewet 23 erww 4.21 ewet 32 ewq 2.32 asdd 91 fdgs 3.43 ewet 123 refs 3.22 asdd 123 refs 4.32 asdd 43 rewq 2.12 ewet # alpha sort on column 4, then numeric on column 1, then reverse # numeric on column 3 print fieldsort [4, '1n', '-3n'], @data; 32 ewq 2.32 asdd 123 refs 4.32 asdd 123 refs 3.22 asdd 123 asd 1.22 asdd 23 erww 4.21 ewet 43 rewq 2.12 ewet 51 erwt 34.2 ewet 91 fdgs 3.43 ewet # now, splitting on either literal period or whitespace # sort numeric on column 4 (fractional part of decimals) then # numeric on column 3 (whole part of decimals) print fieldsort '(?:\.|\s+)', ['4n', '3n'], @data; 51 erwt 34.2 ewet 43 rewq 2.12 ewet 23 erww 4.21 ewet 123 asd 1.22 asdd 123 refs 3.22 asdd 32 ewq 2.32 asdd 123 refs 4.32 asdd 91 fdgs 3.43 ewet # alpha sort on column 4, then numeric on the entire line # NOTE: produces warnings under -w print fieldsort [4, '0n'], @data; 32 ewq 2.32 asdd 123 asd 1.22 asdd 123 refs 3.22 asdd 123 refs 4.32 asdd 23 erww 4.21 ewet 43 rewq 2.12 ewet 51 erwt 34.2 ewet 91 fdgs 3.43 ewet # stable alpha sort on column 4 (maintains original relative order # among items that compare the same) print stable_fieldsort [4], @data; 123 asd 1.22 asdd 32 ewq 2.32 asdd 123 refs 3.22 asdd 123 refs 4.32 asdd 43 rewq 2.12 ewet 51 erwt 34.2 ewet 23 erww 4.21 ewet 91 fdgs 3.43 ewet =head1 BUGS Some rudimentary tests now. Perhaps something should be done to catch things like: fieldsort '.', [1, 2], @lines; C<'.'> translates to C -- probably not what you want. Passing blank lines and/or lines containing the wrong kind of data (alphas instead of numbers) can result in copious warning messages under C<-w>. If the regexp contains memory parentheses (C<(...)> rather than C<(?:...)>), split will function in "delimiter retention" mode, capturing the contents of the parentheses as well as the stuff between the delimiters. I could imagine how this could be useful, but on the other hand I could also imagine how it could be confusing if encountered unexpectedly. Caveat sortor. Not really a bug, but if you are planning to sort a large text file, consider using sort(1). Unless, of course, your operating system doesn't have sort(1). =head1 AUTHOR Joseph N. Hall, C<< >> =head1 SEE ALSO perl(1). =cut Sort-Fields-1.003/Makefile.PL0000644000076500000240000000624514777254773014636 0ustar brianstaffpackage Sort::Fields; use strict; use warnings; =encoding utf8 =head1 The build file for Sort::Fields This build file is a modulino; it works as both a build script and a module. To build the distribution, run this file normally: % perl Makefile.PL But, it's more interesting than that. You can load it with C and call C to get the data structure it passes to C: my $package = require '/path/to/Makefile.PL'; my $arguments = $package->arguments; Note that C-ing a file makes an entry in C<%INC> for exactly that name. If you try to C another file with the same name, even from a different path, C thinks it has already loaded the file. As such, I recommend you always require the full path to the file. The return value of the C is a package name (in this case, the name of the main module. Use that to call the C method. Even if this distribution needs a higher version of Perl, this bit only needs v5.8. You can play with the data structure with a primitive Perl. =cut use File::Spec::Functions qw(catfile); my $module = __PACKAGE__; ( my $dist = $module ) =~ s/::/-/g; my $github = 'https://github.com/briandfoy/sort-fields'; my $main_file = catfile( 'lib', split /::/, "$module.pm" ); my %WriteMakefile = ( 'MIN_PERL_VERSION' => '5.008', 'NAME' => $module, 'ABSTRACT_FROM' => $main_file, 'VERSION_FROM' => $main_file, 'LICENSE' => 'perl', 'AUTHOR' => 'Joseph N. Hall ', 'CONFIGURE_REQUIRES' => { 'ExtUtils::MakeMaker' => '6.64', 'File::Spec::Functions' => '0', }, 'BUILD_REQUIRES' => { }, 'TEST_REQUIRES' => { 'Test::More' => '1', 'version' => '0.86', }, 'PREREQ_PM' => { }, 'META_MERGE' => { 'meta-spec' => { version => 2 }, resources => { repository => { type => 'git', url => $github, web => $github, }, bugtracker => { web => "$github/issues", }, homepage => $github, }, }, clean => { FILES => "$dist-*" }, ); sub arguments { \%WriteMakefile } do_it() unless caller; sub do_it { require File::Spec; my $MM ='ExtUtils::MakeMaker'; my $MM_version = eval{ "$MM " . $WriteMakefile{'CONFIGURE_REQUIRES'}{'ExtUtils::MakeMaker'} } || "$MM 6.64"; eval "use $MM_version; 1" or die "Could not load $MM_version: $@"; eval "use Test::Manifest 1.21" if -e File::Spec->catfile( qw(t test_manifest) ); my $arguments = arguments(); my $minimum_perl = $arguments->{MIN_PERL_VERSION} || '5.008'; eval "require $minimum_perl;" or die $@; WriteMakefile( %$arguments ); } no warnings; __PACKAGE__; sub arguments { \%WriteMakefile } do_it() unless caller; sub do_it { require File::Spec; my $MM ='ExtUtils::MakeMaker'; my $MM_version = eval{ "$MM " . $WriteMakefile{'CONFIGURE_REQUIRES'}{'ExtUtils::MakeMaker'} } || "$MM 6.64"; eval "use $MM_version; 1" or die "Could not load $MM_version: $@"; eval "use Test::Manifest 1.21" if -e File::Spec->catfile( qw(t test_manifest) ); my $arguments = arguments(); my $minimum_perl = $arguments->{MIN_PERL_VERSION} || '5.008'; eval "require $minimum_perl;" or die $@; WriteMakefile( %$arguments ); } no warnings; __PACKAGE__; Sort-Fields-1.003/INSTALL.SKIP0000644000076500000240000000015614777254773014455 0ustar brianstaffREADME\.pod README.* # things that might be in local directories after fooling # around with them \.DS_Store Sort-Fields-1.003/SECURITY.md0000644000076500000240000000230514777254773014446 0ustar brianstaff# Security Policy for Sort::Fields ## Reporting security issues **Do not report security problems on public forums or in repository issues.** Privately report vulnerabilities to the maintainers listed at the end of this document. Include as many details as possible to reproduce the issue, including code samples or test cases. Check that your report does not expose any of your sensitive data, such as passwords, tokens, or other secrets. You do not need to have a solution or fix. Depending on the issue, CPANSec may be notified. Depending on the issue, CPANSec may be notified. You can also privately report issues to the CPAN Security Group (CPANSec) . This is especially important if you think a vulnerability is being actively exploited. CPANSec may report the issue to the relevant authorities. See [Report a Security Issue](https://security.metacpan.org/docs/report.html). ## Response to reports The maintainers aim to respond to all reports within one day, but this may be affected by life and other things that happen to people who maintain open source code. A new release will be provided as soon as possible. ## Maintainers * brian d foy, Sort-Fields-1.003/META.json0000664000076500000240000000261314777254774014303 0ustar brianstaff{ "abstract" : "Sort lines containing delimited fields", "author" : [ "Joseph N. Hall " ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 7.70, CPAN::Meta::Converter version 2.150010", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "Sort-Fields", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : {} }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "6.64", "File::Spec::Functions" : "0" } }, "runtime" : { "requires" : { "perl" : "5.008" } }, "test" : { "requires" : { "Test::More" : "1", "version" : "0.86" } } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/briandfoy/sort-fields/issues" }, "homepage" : "https://github.com/briandfoy/sort-fields", "repository" : { "type" : "git", "url" : "https://github.com/briandfoy/sort-fields", "web" : "https://github.com/briandfoy/sort-fields" } }, "version" : "1.003", "x_serialization_backend" : "JSON::PP version 4.16" }