In Perl 6, you can use the
>> operator to run a named piece of code (a subroutine) on each member of a list / array, returning to you a new list / array of transformed members. For example, the following code reads in all lines from a data file, splits them into individual records, and transforms each record using a
sub called getGrowth.
my @stations = slurp("rstats2015.txt").chomp.split("\n");
my @opposite = @stations>>.&getGrowth;
Complete code - including the getGrowth sub -
[here].
At Well House Consultants, we offer training in Perl 5 and - now that there's an official release out there - we're starting Perl 6 courses very soon. Please take a look at our
Perl course page for more details of our plans, and in these early adaptor days, please ask if you don't see exactly what you're looking for - we can help and tailor training whether you're a newcomer to programming, a Perl 5 geek already, or (more likely for most readers) somewhere in between!
(written 2016-01-03)
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
P208 - Perl - Lists [28] Perl for breakfast - (2004-08-25)
[140] Comparison Chart for Perl programmers - list functions - (2004-12-04)
[230] Course sizes - beware of marketing statistics - (2005-02-27)
[240] Conventional restraints removed - (2005-03-09)
[355] Context in Perl - (2005-06-22)
[463] Splitting the difference - (2005-10-13)
[560] The fencepost problem - (2006-01-10)
[622] Queues and barrel rolls in Perl - (2006-02-24)
[762] Huge data files - what happened earlier? - (2006-06-15)
[773] Breaking bread - (2006-06-22)
[928] C++ and Perl - why did they do it THAT way? - (2006-11-16)
[968] Perl - a list or a hash? - (2006-12-06)
[1304] Last elements in a Perl or Python list - (2007-08-16)
[1316] Filtering and altering Perl lists with grep and map - (2007-08-23)
[1703] Perl ... adding to a list - end, middle, start - (2008-07-09)
[1828] Perl - map to process every member of a list (array) - (2008-10-09)
[1917] Out of memory during array extend - Perl - (2008-12-02)
[1918] Perl Socket Programming Examples - (2008-12-02)
[2067] Perl - lists do so much more than arrays - (2009-03-05)
[2226] Revision / Summary of lists - Perl - (2009-06-10)
[2295] The dog is not in trouble - (2009-07-17)
[2484] Finding text and what surrounds it - contextual grep - (2009-10-30)
[2813] Iterating over a Perl list and changing all items - (2010-06-15)
[2833] Fresh Perl Teaching Examples - part 2 of 3 - (2010-06-27)
[2996] Copying - duplicating data, or just adding a name? Perl and Python compared - (2010-10-12)
[3400] $ is atomic and % and @ are molecular - Perl - (2011-08-20)
[3548] Dark mornings, dog update, and Python and Lua courses before Christmas - (2011-12-10)
[3669] Stepping through a list (or an array) in reverse order - (2012-03-23)
[3870] Writing more maintainable Perl - naming fields from your data records - (2012-09-25)
[3906] Taking the lead, not the dog, for a walk. - (2012-10-28)
[3939] Lots of ways of doing the same thing in Perl - list iteration - (2012-12-03)
P600 - Perl 6 [582] DWIM and AWWO - (2006-01-30)
[2816] Intelligent Matching in Perl - (2010-06-18)
[4604] Perl - version 6 - official version launched at Christmas - (2016-01-02)
[4605] Hello World - in Perl 6 - (2016-01-02)
[4606] Using Perl 6 to analyse and report on data - (2016-01-02)
[4607] Classes and object - first steps in Perl 6 - (2016-01-02)
[4608] Introspecion in Perl 6 - (2016-01-02)
[4610] Sorting by key or by comparator - Perl 6 - (2016-01-03)
[4611] Hungarian, Camel, Snake and Kebab - variable naming conventions - (2016-01-03)
[4620] Perl 6 - a Practical Extraction and Reporting example! - (2016-01-11)
Some other Articles
Our best hotel customers help us ... to help them ... be our best customers.TransWilts - robust these days - no longer the first service to be cancelledMapping an array / list without a loop - how to do it in Perl 6