Download Shareware and Freeware Software for Windows, Linux, Macintosh, PDA

line Home  |  About Us  |  Link To Us  |  FAQ  |  Contact

Serving Software Downloads in 976 Categories, Downloaded 40.284.958 Times

Perl6::Gather 0.04

  Date Added: September 23, 2010  |  Visits: 716


Report Broken Link
Printer Friendly Version

Product Homepage
Download (81 downloads)

Perl6::Gather is a Perl module that implements the Perl 6 gather/take control structure in Perl 5. SYNOPSIS use Perl6::Gather; @list = gather { # Try to extract odd numbers and odd number names... for (@data) { if (/(one|three|five|nine)$/) { take qq{$_}; } elsif (/^d+$/ && $_ %2) { take; } } # But use the default set if there arent any of either... take @defaults unless gathered; } BACKGROUND Perl 6 provides a new control structure -- gather -- that allows lists to be constructed procedurally, without the need for a temporary variable. Within the block/closure controlled by a gather any call to take pushes that calls argument list to an implicitly created array. take returns the number of elements it took. At the end of the blocks execution, the gather returns the list of values stored in the array (in a list context) or a reference to the array (in a scalar context). For example, instead of writing: # Perl 6 code... print do { my @wanted; for <> -> $line { push @wanted, $line if $line ~~ /D/; push @wanted, -$line if some_other_condition($line); } push @wanted, EOF; @wanted; }; in Perl 6 we can write: # Perl 6 code... print gather { for <> -> $line { take $line if $line ~~ /D/; take -$line if some_other_condition($line); } take EOF; } and instead of: $text = do { my $string; for <> { next if /^#|^s*$/; last if /^__[DATA|END]__n$/; $string .= $_; } $string; }; we could write: $text = ~gather { for <> { next if /^#|^s*$/; last if /^__[DATA|END]__n$/; take; } } As the above example implies, if take is called without any arguments, it takes the current topic. There is also a third function -- gathered -- which returns a reference to the implicit array being gathered. This is useful for handling defaults: @odds = gather { for @data { take if $_ % 2; take to_num($_) if /[one|three|five|nine]$/; } take 1,3,5,7,9 unless gathered; } Its also handy for creating the implicit array by some process more complex than by simple sequential pushing. For example, if we needed to prepend a count of non-numeric items: @odds = gather { for @data { take if $_ %2; take to_num($_) if /[one|three|five|nine]$/; } unshift gathered, +grep(/[a-z]/i, @data); } Conceptually gather/take is the generalized form from which both map and grep derive. That is, we could implement those two functions as: sub map ($transform is Code, *@list) { return gather { for @list { take $transform($_) } }; } sub grep ($selected is Code|Rule, *@list) { return gather { for @list { take when $selected } } } A gather is also a very handy way of short-circuiting the construction of a list. For example, suppose we wanted to generate a single sorted list of lines from two sorted files, but only up to the first line they have in common. We could gather the lines like this: my @merged_diff = gather { my $a = < $fh_a >; my $b = < $fh_b >; loop { if defined all $a,$b { if $a eq $b { last } # Duplicate means end of list elsif $a lt $b { take $a; $a = < $fh_a >; } else { take $b; $b = < $fh_b >; } } elsif defined $a { take $a; $a = < $fh_a >; } elsif defined $b { take $b; $b = < $fh_b >; } else { last } } }.

Requirements: No special requirements
Platforms: Linux
Keyword: Control Structure Gather Libraries Line List Perl Perl Module Programming
Users rating: 0/10

License: Freeware Size: 5.12 KB
More Reviews or Write Review

Libraries  -  Alien Perl module 0.91
Alien Perl module package contains external libraries wrapped up for your viewing pleasure! SYNOPSIS perldoc Alien; Alien is a package that exists just to hold together an idea, the idea of Alien:: packages, so there is no code here, just...
10.24 KB  
Libraries  -  I18N::LangTags::List 0.35
I18N::LangTags::List Perl module contains tags and names for human languages. SYNOPSIS use I18N::LangTags::List; print "Parlez-vous... ", join(, , I18N::LangTags::List::name(elx) || unknown_language, I18N::LangTags::List::name(ar-Kw) ||...
30.72 KB  
Libraries  -  OpenGeoDB Perl module 0.4
OpenGeDB Perl module is a module to access the OpenGeoDB database and calculate all ZIP codes in a certain radius..
3.07 KB  
Network & Internet  -  MyCMS perl module 1.0
MyCMS perl module provides the MN::CMS Perl module used by the MyCMS. MyCMS perl module contains Perl object classes to manage the data of MyCMS (such as articles, links, and images). MN::CMS is a perl module that allows you to manage an...
16.38 KB  
Libraries  -  List::MRU 0.04
List::MRU is a Perl module that implements a simple fixed-size MRU-ordered list. SYNOPSIS use List::MRU; # Constructor $lm = List::MRU->new(max => 20); # Constructor with explicit eq subroutine for obj equality tests $lm =...
4.1 KB  
Libraries  -  List::Search 0.3
List::Search is a Perl module for fast searching of sorted lists. SYNOPSIS use List::Search qw( list_search nlist_search custom_list_search ); # Create a list to search my @list = sort qw( bravo charlie delta ); # Search for a value,...
5.12 KB  
Programming  -  Perl Module Manager
Perl Module Manager helps you to install, un-install and manage Perl modules from a CPAN site and other sources in an easy and intuitive way. Allows you to search through thousands of useful modules and libraries on a CPAN site and its mirrors....
1.44 MB  
Libraries  -  Scrape::USPS::ZipLookup Perl Module 2.4
The United States Postal Service (USPS) has on its web site an HTML form at for standardizing an address. Given a firm, urbanization, street address, city, state, and zip, it will put the address into standard form...
11.26 KB  
Science  -  Bio::Parse::SwissProt - perl module 0.5
A Perl module that provides methods for retrieving each and every field from a standard SwissProt file.
9.61 KB  
Benchmark Tools  -  Stopwatch Perl Module 0.10.3
Perf::Stopwatch is a Perl Module that can be quickly added and removed from any existing code to debug/optimize portions of code. Example of use are: database calls, loop efficiency, total script time, and webpage timeouts.
5.98 KB  
Programming  -  Cedalion for Linux 0.2.6
Cedalion is a programming language that allows its users to add new abstractions and define (and use) internal DSLs. Its innovation is in the fact that it uses projectional editing to allow the new abstractions to have no syntactic limitations.
471.04 KB  
Programming  -  Math::GMPf 0.29
Math::GMPf - perl interface to the GMP library's floating point (mpf) functions.
30.72 KB  
Programming  -  Net::Wire10 1.08
Net::Wire10 is a Pure Perl connector that talks to Sphinx, MySQL and Drizzle servers. Net::Wire10 implements the low-level network protocol, alias the MySQL wire protocol version 10, necessary for talking to one of the aforementioned...
30.72 KB  
Programming  -  logilab-common 0.56.2
a bunch of modules providing low level functionnalities shared among some python projects devel Please note that some of the modules have some extra dependencies. For instance, logilab.common.db will require a db-api 2.0 compliant...
174.08 KB  
Programming  -  OpenSSL for linux 1.0.0a
The OpenSSL Project is a collaborative effort to develop a robust, commercial-grade, full-featured, and Open Source toolkit implementing the Secure Sockets Layer (SSL v2/v3) and Transport Layer Security (TLS v1) protocols as well as a...
3.83 MB  
Libraries  -  wolfSSL 4.0.0
The wolfSSL embedded SSL/TLS library is a lightweight SSL library written in ANSI standard C and targeted for embedded and RTOS environments - primarily because of its small size, speed, and feature set. It is commonly used in standard operating...
3.88 MB  
Libraries  -  EuGTK 4.8.9
Makes it easy to develop good- looking, fast, cross-platform programs that run on Linux, OS X, and Windows. Euphoria is a very fast interpreted/compiled language with straight-forward syntax. EuGTK allows programming in a clean, object-oriented...
10.68 MB  
Libraries  -  Linux User Group Library Manager 1.0
The LUG Library Manager is a project to help Linux User Groups start their own library. A LUG library is helpful to the community at large because it increases access to information, and gives everyone the opportunity to become more knowledgeable.
5.35 KB  
Libraries  -  Module::MakefilePL::Parse 0.12
Module::MakefilePL::Parse is a Perl module to parse required modules from Makefile.PL. SYNOPSIS use Module::MakefilePL::Parse; open $fh, Makefile.PL; $parser = Module::MakefilePL::Parse->new( join("", ) ); $info = $parser->required;...
8.19 KB  
Libraries  -  sqlpp 0.06
sqlpp Perl package is a SQL preprocessor. sqlpp is a conventional cpp-alike preprocessor taught to understand SQL ( PgSQL, in particular) syntax specificities. In addition to the standard #define/#ifdef/#else/#endif cohort, provides also...
10.24 KB