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 31.348.774 Times

Perl6::Gather 0.04

  Date Added: September 23, 2010  |  Visits: 594


Report Broken Link
Printer Friendly Version

Product Homepage
Download (71 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
Libraries  -  List::Intersperse 1.00
List::Intersperse Perl module can intersperse / unsort / disperse a list. SYNOPSIS use List::Intersperse qw/intersperseq/; @ispersed = intersperseq {substr($_[0],0,1)} qw/A1 A2 B1 B2 C1 C2/; @ispersed = List::Intersperse::intersperse qw/A...
2.05 KB  
Libraries  -  Convert::Wiki::Node::Line 0.05
Convert::Wiki::Node::Line is a Perl module that represents a horizontal line (aka ruler). SYNOPSIS use Convert::Wiki::Node::Line; my $hr = Convert::Wiki::Node::Line->new( ); print $hr->as_wiki(); A Convert::Wiki::Node::Line represents a...
19.46 KB  
Libraries  -  List::Util 1.19
List::Util Perl module contains a selection of general-utility list subroutines. SYNOPSIS use List::Util qw(first max maxstr min minstr reduce shuffle sum); List::Util contains a selection of subroutines that people have expressed would be...
44.03 KB  
Libraries  -  Sort::Versions 1.5
Sort::Versions is a Perl 5 module for sorting of revision-like numbers. SYNOPSIS use Sort::Versions; @l = sort { versioncmp($a, $b) } qw( 1.2 1.2.0 1.2a.0 1.2.a 1.a 02.a ); ... use Sort::Versions; print lower if versioncmp(1.2, 1.2a) ==...
5.12 KB  
Libraries  -  Wx::Perl::Packager 0.07
Wx::Perl::Packager provides a module to assist packaging Wx based applications with PAR, ActiveState PerlApp / PDK and Perl A module to assist packaging Wx based applications with PAR, ActiveState PerlApp / PDK and Perl2Exe. All that is needed...
12.29 KB  
Libraries  -  OzDB 0.02
OzDB is a database Perl interface module for OzBot. SYNOPSIS use OzDB; The OzDB Perl module handles authentication and access control for the OzBot based utility bots. The basic database format is the authentication schema. This is based on...
12.29 KB  
Libraries  -  perlrpcgen 0.71
perlrpcgen is a Perl module that can generate Perl interfaces from ONC RPC interface definitions. SYNOPSIS perlrpcgen [--makefile] [--all] [--client] [--server] [--data] [--constants] [--module module] [--typemap typemap] [--fork] [--perl...
37.89 KB  
Libraries  -  Tuxedo 2.08
Tuxedo is a Perl extension module for Tuxedo. This module provides the following functionality... C style interface The Tuxedo perl module gives you access to almost all of the tuxedo 8.1 apis from perl. In most cases you can take the C API...
33.79 KB  
Libraries  -  GPIB::hpe3631a 0.30
GPIB::hpe3631a is a Perl-GPIB module for HPE3631A power supply. SYNOPSIS use GPIB::hpe3631a; $g->GPIB::hpe3631a->new("name"); $g->output(1); # Outputs on $g->output(0); # Outputs off $v = $g->output; # Read output state $g->track(1); #...
74.75 KB  
Libraries  -  Net::Whois::RIPE 1.23
Net::Whois::RIPE is an object-oriented Perl library module that provides methods to query, retrieve, and update RIPE-157 formatted objects from whois servers that support this format. In particular, both the Asian and European Internet...
32.77 KB  
Programming  -  FLEX-db Digital Asset Manager 3.0.9
FLEX-db - an enterprise Digital Asset Manager (DAM). It ingests and links metadata with files, creates thumbnails, and processes files using business rules. FLEX-db has a JSP client, Java app server for file input and output and an EJB metadata...
21.57 MB  
Programming  -  Libicom 0.9.0
The libicom library is a character based dynamicly linked library for Linux. It is used to remotely control the Icom IC-R8500 wide band receiver via an RS232 link. All call and return parameters to the control functions are character string based....
20.48 KB  
Programming  -  dotdesktop 0.3
Dotdesktop library provides ability to parse desktop entry file and access the information in a convenient way. Desktop entry file format is defined by, it is used to describe information about an application such as the name and...
327.68 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  -  libyasl 0.2
Libyasl is a C++ class library to easily realize TCP/UDP/Multicast clientsand servers in IPv4 and IPv6 environments under GNU/Linux systems.
143.36 KB  
Libraries  -  wolfSSL 3.13.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