|
SDF::Sort::Bubble - Sort an PTools::SDF::SDF object on specified key field |
SDF::Sort::Bubble - Sort an PTools::SDF::SDF object on specified key field(s)
This document describes version 0.08, released March, 2005.
use PTools::SDF::SDF; # or any subclass thereof, including:
use PTools::SDF::ARRAY;
use PTools::SDF::IDX;
use PTools::SDF::DIR;
use PTools::SDF::DSET;
$sdfObj = new PTools::SDF::SDF( $fileName );
$sdfObj->extend( "sort", "PTools::SDF::Sort::Bubble" );
$sdfObj->sort( $mode, @keyFields );
($stat,$err) = $sdfObj->status;
$stat and die $err;
This sort class is one of several extended classes used to select which algorithm is employed to sort data in the calling object. It is up to the client script to select the specific algorithm, as shown in the Synopsis section, above.
By default this class will be used to sort the data, unless one of the other sort classes is specified via the extend method in PTools::SDF::SDF.
The tradeoff is flexibility vs performance. This is by far the slowest sort algorithm but is also the most flexible. Even so, for files containing no more than 100 records, all of the sort modules are roughly equivalent in speed.
The interface of this sort method is documented here. This is the intended usage for clients of the PTools::SDF::* class of objects.
The actual calling syntax for module designers is shown in the following section, below.
This class will attempt to determine whether numeric or character sorting should occur for each of the KeyFields passed, based on the values in the first two records in the object containing data.
At least two records must exist in the containing PTools::SDF::SDF object or an exception is generated.
rev reverse - to sort in reverse order ignore ignorecase - ignore case sensitivity during the sort
Any combination of the above may be used
rev:ignorecase
Using reverse sorting with multiple KeyFields should be 'experimented with' to ensure the desired results are obtained.
Keys can be passed either in a simple array or as a colon separated list.
At least one key field must be passed or an exception is generated.
Example:
use PTools::SDF::IDX;
$idxObj = new PTools::SDF::IDX( "/etc/passwd" );
$sdfObj->sort( undef, "uname" );
($stat,$err) = $sdfObj->status;
$stat and die $err;
Of course, this just an example. It would be appropriate to use the PTools::SDF::File::Passwd class instead as this provides additional methods for manipulating password file data.
The actual calling syntax for module designers is documented here. This is the syntax used when invoking this method from withn the extended sort method of the PTools::SDF::SDF class only.
The user interface of this sort method is shown in the preceeding section.
The other parameters are the same as explained above.
None currently.
Other extended sort classes are available. See the PTools::SDF::Sort::Quick manpage, the PTools::SDF::Sort::Random manpage and the PTools::SDF::Sort::Shell manpage.
Also see the PTools::SDF::Overview manpage, the PTools::SDF::ARRAY manpage, the PTools::SDF::CSV manpage, the PTools::SDF::DB manpage, the PTools::SDF::DIR manpage, the PTools::SDF::DSET manpage, the PTools::SDF::File manpage, the PTools::SDF::IDX manpage, the PTools::SDF::INI manpage, the PTools::SDF::SDF manpage, the PTools::SDF::TAG manpage and the PTools::SDF::Lock::Advisory manpage.
Chris Cobb, <nospamplease@ccobb.net>
Copyright (c) 1997-2007 by Chris Cobb. All rights reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
|
SDF::Sort::Bubble - Sort an PTools::SDF::SDF object on specified key field |