home *** CD-ROM | disk | FTP | other *** search
-
- <HTML>
- <HEAD>
- <TITLE>Sort::PolySort -- general rules-based sorting of lists</TITLE>
- <LINK REL="stylesheet" HREF="../../../Active.css" TYPE="text/css">
- <LINK REV="made" HREF="mailto:">
- </HEAD>
-
- <BODY>
- <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
- <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
- <STRONG><P CLASS=block> Sort::PolySort -- general rules-based sorting of lists</P></STRONG>
- </TD></TR>
- </TABLE>
-
- <A NAME="__index__"></A>
- <!-- INDEX BEGIN -->
-
- <UL>
-
- <LI><A HREF="#name">NAME</A></LI><LI><A HREF="#supportedplatforms">SUPPORTED PLATFORMS</A></LI>
-
- <LI><A HREF="#synopsis">SYNOPSIS</A></LI>
- <LI><A HREF="#description">DESCRIPTION</A></LI>
- <UL>
-
- <LI><A HREF="#methods">METHODS</A></LI>
- <LI><A HREF="#specs">Specs</A></LI>
- <LI><A HREF="#parsing scheme">Parsing Scheme</A></LI>
- <LI><A HREF="#named specs">Named Specs</A></LI>
- </UL>
-
- <LI><A HREF="#errors">ERRORS</A></LI>
- <LI><A HREF="#notes">NOTES</A></LI>
- <LI><A HREF="#author">AUTHOR</A></LI>
- <LI><A HREF="#copyright">COPYRIGHT</A></LI>
- </UL>
- <!-- INDEX END -->
-
- <HR>
- <P>
- <H1><A NAME="name">NAME</A></H1>
- <PRE>
- Sort::PolySort -- general rules-based sorting of lists</PRE>
- <P>
- <HR>
- <H1><A NAME="supportedplatforms">SUPPORTED PLATFORMS</A></H1>
- <UL>
- <LI>Linux</LI>
- <LI>Solaris</LI>
- <LI>Windows</LI>
- </UL>
- <HR>
- <H1><A NAME="synopsis">SYNOPSIS</A></H1>
- <PRE>
- use Sort::PolySort;
- $s=new Sort::PolySort; # defaults to 'name'
- @people=('John Doe','Jane Doll','John Quasimodo Doe');
- print join(", ",$s->sort(@people),"\n";
- </PRE>
- <PRE>
-
- use Sort::PolySort;
- $s=new Sort::PolySort('dateus'); # sets internal
- @dates=$s->sort(@dates); # uses internal
- $s->by('email'); # sets internal
- @names=$s->sortby('name',@names); # overrides internal
- @emails=$s->sort(@emails); # internal is still 'email'</PRE>
- <P>
- <HR>
- <H1><A NAME="description">DESCRIPTION</A></H1>
- <P>This module provides methods to sort a list of strings based on
- parsing the strings according to a configurable set of specifications.</P>
- <P>
- <H2><A NAME="methods">METHODS</A></H2>
- <P>The following methods are available:</P>
- <DL>
- <DT><STRONG><A NAME="item_new"><EM>new</EM></A></STRONG><BR>
- <DD>
- Creates a new polysort object. Takes optional arguement of initial
- named spec set (defaults to <EM>name</EM>).
- <P></P>
- <DT><STRONG><A NAME="item_by"><EM>by</EM></A></STRONG><BR>
- <DD>
- Configures for the named set of sorting specs. Arguement is name of spec set.
- <P></P>
- <DT><STRONG><A NAME="item_sort"><EM>sort</EM></A></STRONG><BR>
- <DD>
- Sorts by the previously-set (by <EM>new</EM> or <EM>by</EM>) specs. Arguement is a
- list of items to sort. Returns the sorted list, leaving the original
- unchanged.
- <P></P>
- <DT><STRONG><A NAME="item_sortby"><EM>sortby</EM></A></STRONG><BR>
- <DD>
- Sorts by the given (named) set of specs. The specs are only changed for
- this particular sort, so future calls to <EM>sort</EM> will use whatever
- specs were in effect before the <EM>sortby</EM> call. First arguement is
- name of spec set, second arguement is a list of items to sort. Returns
- the sorted list, leaving the original unchanged.
- <P></P>
- <DT><STRONG><A NAME="item_get"><EM>get</EM></A></STRONG><BR>
- <DD>
- Returns an associative array of the current sort specs. See <A HREF="#notes">NOTES</A>.
- <P></P>
- <DT><STRONG><A NAME="item_set"><EM>set</EM></A></STRONG><BR>
- <DD>
- Sets the current sort specs to the given associative array. Specs not
- appearing in the passed array retain their previous values, so this
- method can be used along with <EM>get</EM> to keep state during a subroutine
- call or to alter particular specs to get new sorting
- results. Arguement is an associative array. See <A HREF="#notes">NOTES</A>.
- <P></P></DL>
- <P>
- <H2><A NAME="specs">Specs</A></H2>
- <P>The following specifications are local to each Sort::PolySort object:</P>
- <DL>
- <DT><STRONG><A NAME="item_GLOBTOP"><CODE>GLOBTOP</CODE></A></STRONG><BR>
- <DD>
- Lump last two levels together?
- <P></P>
- <DT><STRONG><A NAME="item_LEVELS"><CODE>LEVELS</CODE></A></STRONG><BR>
- <DD>
- Number of levels to consider (0=all)
- <P></P>
- <DT><STRONG><A NAME="item_R2L"><CODE>R2L</CODE></A></STRONG><BR>
- <DD>
- Count fields right to left?
- <P></P>
- <DT><STRONG><A NAME="item_NUMERIC"><CODE>NUMERIC</CODE></A></STRONG><BR>
- <DD>
- Do numerical sort?
- <P></P>
- <DT><STRONG><A NAME="item_CASE"><CODE>CASE</CODE></A></STRONG><BR>
- <DD>
- Do case-sensitive sort?
- <P></P>
- <DT><STRONG><A NAME="item_DELIM1"><CODE>DELIM1</CODE></A></STRONG><BR>
- <DD>
- Primary element delimiter (must not be null).
- <P></P>
- <DT><STRONG><A NAME="item_DELIM2"><CODE>DELIM2</CODE></A></STRONG><BR>
- <DD>
- Secondary element delimiter (can be null).
- <P></P></DL>
- <P>
- <H2><A NAME="parsing scheme">Parsing Scheme</A></H2>
- <P>The following order is followed to determine the keys used to sort the
- given array:</P>
- <OL>
- <LI>
- <EM>DELIM2</EM> (if given)
- <P>Remove up to leftmost (rightmost if <EM>R2L</EM> is true) occurance of <EM>DELIM2</EM>
- (will be brought back later).</P>
- <P></P>
- <LI>
- <EM>DELIM1</EM>
- <P>Split remainder at all occurances of <EM>DELIM1</EM>.</P>
- <P></P>
- <LI>
- <EM>GLOBTOP</EM> (if true)
- <P>Rejoin left (right if <EM>R2L</EM> is true) 2 elements (always joined left-to-right,
- regardless of <EM>R2L</EM>).</P>
- <P></P>
- <LI>
- <EM>R2L</EM> (if true)
- <P>Reverse list of elements.</P>
- <P></P>
- <LI>
- <EM>LEVELS</EM>
- <P>Store first <EM>LEVELS</EM> (all if =0) elements (last 2 considered as a
- single element if <EM>GLOBTOP</EM> is true).</P>
- <P></P>
- <LI>
- <EM>DELIM2</EM> (if true)
- <P>Store string from left of <EM>DELIM2</EM> as next element.</P>
- <P></P>
- <LI>
- <EM>LEVELS</EM> (unless 0)
- <P>Rejoin remaining elements (in original order, regardless of <EM>R2L</EM>) and
- store as next element.</P>
- <P></P></OL>
- <P>
- <H2><A NAME="named specs">Named Specs</A></H2>
- <P>The following (case-sensitive) names are used by <EM>new</EM>, <EM>by</EM> and
- <EM>sortby</EM> to represent pre-defined sets of specs:</P>
- <DL>
- <DT><STRONG><A NAME="item_datebr"><EM>datebr</EM></A></STRONG><BR>
- <DD>
- by European (dd/mm/yy) date
- <P></P>
- <DT><STRONG><A NAME="item_dateus"><EM>dateus</EM></A></STRONG><BR>
- <DD>
- by US-style (mm/dd/yy) date
- <P></P>
- <DT><STRONG><A NAME="item_email"><EM>email</EM></A></STRONG><BR>
- <DD>
- by user for each machine (all parts of FQDN)
- <P></P>
- <DT><STRONG><A NAME="item_email2"><EM>email2</EM></A></STRONG><BR>
- <DD>
- by user for each top-level domain (last 2 atoms)
- <P></P>
- <DT><STRONG><A NAME="item_emaild"><EM>emaild</EM></A></STRONG><BR>
- <DD>
- by user for each domain-name (next-to-last atom)
- <P></P>
- <DT><STRONG><A NAME="item_ip"><EM>ip</EM></A></STRONG><BR>
- <DD>
- by numerical (aaa.bbb.ccc.ddd) ip address
- <P></P>
- <DT><STRONG><A NAME="item_name"><EM>name</EM></A></STRONG><BR>
- <DD>
- by last name/first name/middle name or initials
- <P></P></DL>
- <P>
- <HR>
- <H1><A NAME="errors">ERRORS</A></H1>
- <P>The following errors may occur:</P>
- <DL>
- <DT><STRONG><A NAME="item_No_specname_given"><STRONG>No specname given</STRONG></A></STRONG><BR>
- <DD>
- <EM>by</EM> or <EM>sortby</EM> wasn't passed a specname.
- <P></P>
- <DT><STRONG><A NAME="item_Never_heard_of_specname_%60%60foo%27%27"><STRONG>Never heard of specname ``foo''</STRONG></A></STRONG><BR>
- <DD>
- <EM>new</EM>, <EM>by</EM>, or <EM>sortby</EM> was passed a name that was not in the list of
- known specnames.
- <P></P></DL>
- <P>
- <HR>
- <H1><A NAME="notes">NOTES</A></H1>
- <P>The whole parsing method is pretty perverse, but honestly was the first
- thing that came to mind. It works, but is not very fast or extensible.
- Enough interested folks mailed me that I wanted to get this out now, but
- it's dyin' for a rewrite. So this is just a beta. The main interface will
- remain the same, but the parser will be rewritten and the spec variables
- changed. Accessor methods will change as a result (using <CODE>%s=$s-</CODE>get; ...
- ;$s-><A HREF="#item_set"><CODE>set(%s)</CODE></A> will probably still work to save state, though). And accessor
- methods wll be added so that new names spec sets can be added at runtime
- or known ones modified. And new named spec sets will be added. And on and
- on and on...</P>
- <P>
- <HR>
- <H1><A NAME="author">AUTHOR</A></H1>
- <P>Daniel Macks <<A HREF="mailto:dmacks@netspace.org">dmacks@netspace.org</A>></P>
- <P>
- <HR>
- <H1><A NAME="copyright">COPYRIGHT</A></H1>
- <P>Copyright (c) 1996 by Daniel Macks. All rights reserved.
- This module is free software; you may redistribute it
- and/or modify it under the same terms as Perl itself.</P>
- <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
- <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
- <STRONG><P CLASS=block> Sort::PolySort -- general rules-based sorting of lists</P></STRONG>
- </TD></TR>
- </TABLE>
-
- </BODY>
-
- </HTML>
-