I think it is called "Schwartzian Transform". That's why you couldn't find it ;-).
Basically it's a sorting technique for arrays of multiple fields. With it you can sort them according to any fields you prefer.
Suppose you have this data:
-r--r--r-- 1 yourname 8318 Jan 30 1996 file1.txt
-r--r--r-- 1 yourname 11986 Jan 30 1996 file2.txt
-r--r--r-- 1 yourname 46852 Feb 27 1996 file3.txt
-r--r--r-- 1 yourname 72698 Feb 27 1996 file4.txt
And you want to sort them according to size.
You would do it with ST like this:
@sorted_by_size =
map { $_->[0] }
sort { $a->[1] <=> $b->[1] }
map { [$_, -s] }
@files;
So in principle you would do ST in the following step:
1. Map the initial list into a list of ref to lists with the original
+and modified values
2. Sort the list of references
3. Map the list of ref back into a plain list with the initial values
Check this out by the very creator himself - Randal Schwartz ( merlyn).
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|