| |||||||||||
| |||||||||||
Read file, map all lines, sort results and display top 25
this example from a Well House Consultants training course
Source code: mapper Module: P600
#!/usr/bin/env perl6
# Read file, map all lines, sort results and display top 25 # Data file can be downloaded from http://www.wellho.net/data/rstats2015.xyz # or from http://www.wellho.net/data/rstats2015.txt ... be careful not to # convert tabs to spaces as the program relies on a tab seperated file! sub getGrowth($text) { my @fol = $text.split("\t"); my $pg = 1.0; $pg = @fol[*-1] / @fol[7] unless "NULL" ~~ @fol[*-1] | @fol[7]; (@fol[1],@fol[2],@fol[7],@fol[*-1],$pg) } my @stations = slurp("rstats2015.txt").chomp.split("\n"); my @opposite = @stations>>.&getGrowth; @opposite = @opposite.sort({@$^a[4]}); for @opposite[0..25] -> @record { say @record.join(", ") } =finish WomanWithCat:perl6 grahamellis$ perl6 mapper ELO, NG19 9LH, 1310, 88 , 0.067176 LLA, LL42 1AZ, 16198, 1964 , 0.121250 ACK, NE65 4DE, 917, 206 , 0.224646 HEL, DN14 0QN, 714, 182 , 0.254902 CUA, IV27 4ET, 2016, 530 , 0.262897 COE, PL14 7LL, 96, 26 , 0.270833 PIL, BS35 4JT, 245, 68 , 0.277551 GTN, CF11 8UY, 601025, 182814 , 0.3041704 PEG, NE61 6SJ, 3564, 1114 , 0.312570 ABH, LL53 6PJ, 1038, 326 , 0.314066 LEL, TR26 3DS, 8697, 2874 , 0.330459 DNY, YO21 2JL, 23729, 8440 , 0.355683 ISP, OX5 3ED, 18988, 6858 , 0.361175 CLI, M27 8LL, 417, 152 , 0.364508 WBD, DN14 0HH, 1852, 676 , 0.365011 IBM, PA16 0XB, 128741, 47376 , 0.3679947 SWO, CT15 4JH, 18282, 6822 , 0.373154 TPC, PE24 4NL, 738, 284 , 0.384824 GFF, CF81 8LT, 8997, 3606 , 0.400800 CPN, EX37 9DZ, 472, 192 , 0.406780 ADM, CT3 3JE, 53898, 22374 , 0.415117 TEA, DL2 1NL, 74, 32 , 0.432432 WOS, WR4 9EJ, 1355790, 595402 , 0.4391550 BMF, HU15 1RQ, 2912, 1304 , 0.447802 BAV, DN19 7ET, 3521, 1638 , 0.465209 ECS, NR16 2JG, 2358, 1098 , 0.465649 WomanWithCat:perl6 grahamellis$ Learn about this subject
This module and example are covered as required on private courses.
Should you wish to cover this example and associated subjects, and you're attending a public course
to cover other topics with us, please see our extra topic program.
Books covering this topic
Yes. We have over 700 books in our library. Books
covering Perl are listed here and when you've selected a
relevant book we'll link you on to Amazon to order.
Other Examples
This example comes from our "this" training module. You'll find a description of the topic and some
other closely related examples on the "this" module index page.
Full description of the source code
You can learn more about this example on the training courses listed on this page,
on which you'll be given a full set of training notes.
Many other training modules are available for download (for limited use) from our download centre under an Open Training Notes License. Other resources
• Our Solutions centre provides a number of longer technical articles.
• Our Opentalk forum archive provides a question and answer centre. • The Horse's mouth provides a daily tip or thought. • Further resources are available via the resources centre. • All of these resources can be searched through through our search engine • And there's a global index here. Purpose of this website
This is a sample program, class demonstration or answer from a
training course. It's main purpose
is to provide an after-course service to customers who have attended our
public private or
on site courses, but the examples are made
generally available under conditions described below.
Web site author
Conditions of use
Past attendees on our training courses are welcome to use individual
examples in the course of their programming, but must check
the examples they use to ensure that they are suitable for their
job. Remember that some of our examples show you how not to do
things - check in your notes. Well House Consultants take no responsibility
for the suitability of these example programs to customer's needs.
This program is copyright Well House Consultants Ltd. You are forbidden from using it for running your own training courses without our prior written permission. See our page on courseware provision for more details. Any of our images within this code may NOT be reused on a public URL without our prior permission. For Bona Fide personal use, we will often grant you permission provided that you provide a link back. Commercial use on a website will incur a license fee for each image used - details on request. |
| ||||||||||
PH: 01144 1225 708225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho PAGE: http://www.wellho.net/resources/ex.php4 • PAGE BUILT: Sun Oct 11 14:50:09 2020 • BUILD SYSTEM: JelliaJamb |