ADBRITE ads links
You are here: CodeIdol.com > Perl > Intermediate Perl > Practical Reference Tricks
Intermediate Perl
| 9.1. Review of Sorting
Perl's built-in sort operator
sorts text strings in their natural text order, by default.[*] This is fine if we want to sort text strings:[*] My friends call that the "ASCIIbetical" ordering. Normally, modern Per...
|
|
| 9.2. Sorting with Indices
In the same way we used indices to solve a few problems with grep and map back in Chapter 2, we can also use indices with sort to get some interesting results. For example, let's sort the list of names from earlier:...
|
|
| 9.3. Sorting Efficiently
As the Professor tries to maintain the community computing facility (built entirely out of bamboo, coconuts, and pineapples, and powered by a certified Perl-hacking monkey), he continues to discover that people are leav...
|
|
| 9.4. The Schwartzian Transform
The intermediate variables between each of these steps were not necessary, except as input to the next step. We can save ourselves some brainpower by just stacking all the steps together:
my @names ...
|
|
| 9.5. Multi-Level Sort with the Schwartzian Transform
If we need to sort on more than one criterion, the Schwartzian Transform is still up to the task.
my @output_data =
map $_->[0],
sort { SORT COMPARISON USING $a->[1] A...
|
|
| 9.6. Recursively Defined Data
While the data we've processed with references up to this point has been rather fixed structure, sometimes we have to deal with hierarchical data, which is often defined recursively.
For Example One, cons...
|
|
| 9.7. Building Recursively Defined Data
Suppose we wanted to capture information about a filesystem, including the filenames and directory names, and their included contents. Represent a directory as a hash, in which the keys are the names...
|
|
| 9.8. Displaying Recursively Defined Data
The Dumper routine of Data::Dumper displays the output nicely, but what if we don't like the format being used? We can write a routine to display the data. Again, for recursively defined data, a re...
|
|
| 9.9. Exercises
You can find the answers to these exercises in "Answers for Chapter 9" in the Appendix.
9.9.1. Exercise 1 [15 min]
Using the glob operator, a naive sort of every name in the /bin directory by their relative sizes might be writte...
|
|
You are here: CodeIdol.com > Perl > Intermediate Perl > Practical Reference Tricks
|
|
Related tags
Popular Categories
Unix books and guides
AJAX popular information
C# language guides
Windows books and cookbooks
.......
|
|