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

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

Serving Software Downloads in 956 Categories, Downloaded 50.078.844 Times

Array::PatternMatcher 0.04

  Date Added: October 23, 2010  |  Visits: 935

Array::PatternMatcher

Report Broken Link
Printer Friendly Version


Product Homepage
Download (118 downloads)



Array::PatternMatcher is a pattern matching for arrays. SYNOPSIS This section inlines the entire test suite. Please excuse the ok()s. use Array::PatternMatcher; Matching logical variables to input stream # 1 - simple match of logical variable to input my $pattern = AGE ; my $input = 969 ; my $result = pat_match ($pattern, $input, {} ) ; ok($result->{AGE}, 969) ; # 2 - if binding exists, it must equal the input $input = 12; my $new_result = pat_match ($pattern, $input, $result) ; ok(!defined($new_result)) ; # 3 - bind the pattern logical variables to the input list $pattern = [qw(X Y)] ; $input = [ 77, 45 ] ; my $result = pat_match ($pattern, $input, {} ) ; ok($result->{X}, 77) ; Matching segments (quantifying) portions of the input stream # 1 { my $pattern = [a, [qw(X *)], d] ; my $input = [a, b, c, d] ; my $result = pat_match ($pattern, $input, {} ) ; ok ("@{$result->{X}}","b c") ; } # 2 { my $pattern = [a, [qw(X *)], [qw(Y *)], d] ; my $input = [a, b, c, d] ; my $result = pat_match ($pattern, $input, {} ) ; ok ("@{$result->{Y}}","b c") ; } # 3 { my $pattern = [a, [qw(X +)], d] ; my $input = [a, b, c, d] ; ok ("@{$result->{X}}","b c") ; } # 4 { my $pattern = [ a, [qw(X ?)], c ] ; my $input = [ a, b, c ] ; my $result = pat_match ($pattern, $input, {} ) ; ok ("$result->{X}","b") ; } # 5 { my $pattern = [ qw(X OP Y is Z), [ sub { "($_->{X} $_->{OP} $_->{Y}) == $_->{Z}" }, IF? ] ] ; my $input = [qw(3 + 4 is 7) ] ; my $result = pat_match ($pattern, $input, {} ) ; ok ($result) ; } Single-matching: Take a single input and a series of patterns and decide which pattern matches the input: # 1 - Here all input patterns must match the input { my @pattern ; push @pattern, [ qw(X Y) ] ; push @pattern, [ qw(22 Z ) ] ; push @pattern, [ qw(M 33) ] ; my $input = [ qw(22 33) ] ; my $meta_pattern = [ AND?, @pattern ] ; # if no bindings, add a binding between pattern and input my $result = pat_match ($meta_pattern, $input, {} ) ; ok ($result->{Z},33) ; } # 2 - Here, any one of the patterns must match the input { my @pattern ; push @pattern, [ qw(99 22) ] ; push @pattern, [ qw(33 22) ] ; push @pattern, [ qw(44 3) ] ; push @pattern, [ qw(22 Z) ] ; my $input = [ qw(22 33) ] ; my $meta_pattern = [ OR?, @pattern ] ; # if no bindings, add a binding between pattern and input my $result = pat_match ($meta_pattern, $input, {} ) ; ok ($result->{Z},33) ; } # 3 - Here, none of the patterns must match the input { my @pattern ; push @pattern, [ qw(99 22) ] ; push @pattern, [ qw(33 22) ] ; push @pattern, [ qw(44 3) ] ; push @pattern, [ qw(22 Z) ] ; my $input = [ qw(22 33) ] ; my $meta_pattern = [ NOT?, @pattern ] ; # if no bindings, add a binding between pattern and input my $result = pat_match ($meta_pattern, $input, {} ) ; ok (scalar keys %$result == 0) ; } # 4 - here the input must satisfy the predicate { sub numberp { $_[0] =~ /d+/ } my $pattern = [ qw(X age), [qw(IS? N), νmberp] ] ; my $input = [ qw(Mary age), thirty-four ] ; # if no bindings, add a binding between pattern and input my $result = pat_match ($pattern, $input, {} ) ; ok (!defined($result)); } # 5 - same thing, but this time a failing result --- # not undef because it is the return val of numberp { sub numberp { $_[0] =~ /d+/ } my $pattern = [ qw(X age), [qw(IS? N), νmberp] ] ; my $input = [ qw(Mary age), 34 ] ; my $result = pat_match ($pattern, $input, {} ) ; ok ($result->{N},34) ; } Segment-matching: Match a chunk of the input stream using *, +, ? # 1 - * is greedy in this case, but not with 2 consecutve * patterns { my $pattern = [a, [qw(X *)], d] ; my $input = [a, b, c, d] ; # if no bindings, add a binding between pattern and input my $result = pat_match ($pattern, $input, {} ) ; warn sprintf "X*RETVAL: %s", Data::Dumper::Dumper($result) ; ok ("@{$result->{X}}","b c") ; } # 2 - X* gets nothing, Y* gets all it can: { my $pattern = [a, [qw(X *)], [qw(Y *)], d] ; my $input = [a, b, c, d] ; # if no bindings, add a binding between pattern and input my $result = pat_match ($pattern, $input, {} ) ; warn sprintf "X*Y*RETVAL: %s", Data::Dumper::Dumper($result) ; ok ("@{$result->{Y}}","b c") ; } # 3 - samething , but require at least one match for X { my $pattern = [a, [qw(X +)], d] ; my $input = [a, b, c, d] ; my $result = pat_match ($pattern, $input, {} ) ; warn sprintf "RETVAL: @{$result->{X}}" ; ok ("@{$result->{X}}","b c") ; } # 4 - require 0 or 1 match for X { my $pattern = [ a, [qw(X ?)], c ] ; my $input = [ a, b, c ] ; my $result = pat_match ($pattern, $input, {} ) ; ok ("$result->{X}","b") ; } # 5 - evaluate a sub on the fly after match { my $pattern = [ qw(X OP Y is Z), [ sub { "($_->{X} $_->{OP} $_->{Y}) == $_->{Z}" }, IF? ] ] ; my $input = [qw(3 + 4 is 7) ] ; my $result = pat_match ($pattern, $input, {} ) ; ok ($result) ; } # --- 6 same thing, but fail { my $pattern = [ qw(X OP Y is Z), [ sub { "($_->{X} $_->{OP} $_->{Y}) == $_->{Z}" }, IF? ] ] ; my $input = [qw(3 + 4 is 8) ] ; my $result = pat_match ($pattern, $input, {} ) ; warn sprintf "IF_RETVAL2: *%s*", Data::Dumper::Dumper($result); ok ($result eq ) ; }.

Requirements: No special requirements
Platforms: Linux
Keyword: Arraypatternmatcher B C If Input Match Op Pattern Pattern Matching Patternmatcher Qw Result Retval
Users rating: 0/10

License: Freeware Size: 6.14 KB
USER REVIEWS
More Reviews or Write Review


ARRAY::PATTERNMATCHER RELATED
Libraries  -  B::C 5.8.8
B::C is Perl compilers C backend. SYNOPSIS perl -MO=C[,OPTIONS] foo.pl This compiler backend takes Perl source and generates C source code corresponding to the internal structures that perl uses to run your program. When the generated C...
12.2 MB  
Screen Savers  -  B. C. Rich Handcrafted Desktop Set for Mac OS 1.0
The B.C. Rich beautiful guitars.... Bich Bass, Stealth Guitar, Gunslinger Guitar, Draco Guitar. 7 desktop images in all. Guitars you will see No Where Else!
4 MB  
Automation Tools  -  Stop if Input is Empty 1.0
Stop if Input is Empty is a free Automator action that will automatically stop the currently running workflow if its input is empty or null.
40.96 KB  
Libraries  -  Mptn 0.3.0
Mptn project is a library providing a pattern matching mechanism similar to regular expressions, but with several differences making it more suitable for building a morphological analyzer. Differences are: - The whole string is matched against...
102.4 KB  
Text Chat Clients  -  Convex 1.0
Convex provides a flexible pattern matching system designed for creating response driven IRC bots. Convex is a system for creating IRC bots. It features stability, a small memory footprint, a flexible but intuitive configuration system, stealth...
14.34 KB  
Libraries  -  Grid::Transform 0.02
Grid::Transform is a Perl module with fast grid transformations. SYNOPSIS use Grid::Transform; $g = Grid::Transform->new([a..o], rows=>5); $g->rotate_270->flip_vertical; print join( , $g->grid), "n"; The Grid::Transform module provides...
36.86 KB  
Programming  -  Tcl/Tk 8.4.15/8.5a6
Tcl provides a portable scripting environment for Unix, Windows, and Macintosh that supports string processing and pattern matching, native file system access, shell-like control over other programs, TCP/IP networking, timers, and event-driven...
3.1 MB  
Libraries  -  UNIVERSAL::derived_classes 0.01
SYNOPSIS require UNIVERSAL::derived_classes; package A; package B; @ISA = qw( A ); package C; @ISA = qw( B ); package main; my @derived_classes = A->derived_classes; # B, C my @derived_classes_reversed = A->derived_classes_reversed;...
3.07 KB  
Development Tools  -  satang 1.0
-function angles=satang4(strSys1,latA,longA,longsat,strSys2,latB,longB)-calculation of satellite angles: elevation, azimuth, and also relative azimuth and baseline orientation if input data-belongs to two sites-Sources:-Digital satellite...
10 KB  
Development Tools  -  Eigensystem Realization Algorithm 1.0
[A,B,C,D]=era(h,n,N,Ts,def);This function returns the state-space model (A,B,C,D) in continuous or discrete time. The input parameters are the discrete-time impulse response function (IRF); the order of the system; the number of samples to...
10 KB  
NEW DOWNLOADS IN PROGRAMMING, LIBRARIES
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