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

Array::PatternMatcher 0.04

  Date Added: October 23, 2010  |  Visits: 752

Array::PatternMatcher

Report Broken Link
Printer Friendly Version


Product Homepage
Download (102 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
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  
Education  -  Learn the A B C with Kito 1.8
Learn the A B C letters! Trip with a spaceship to the 7 continents! America, Asia, Australia, South America, Europe, Antarctica and Africa! A B C trip is an Educational learning and fun game for kids and toddlers. A visitor from another...
46.4 MB  
Education  -  English Test Level (A,B,C) 2.0.0
Learn, Test English ANYWHERE, ANY TIME The Test English Level is a collection of question test in level A,B,C . It contains about 4000 English lessons (20 questions per test plus answer keys) covering a wide variety of topics and...
13.3 MB  
Business  -  G B C Kommunikationssysteme 3.0.6.0
Jetzt gibt es G B C als offizielle App fur's Smartphone! Alle Neuigkeiten, Fotos, Veranstaltungen und Termine landen so direkt in der Hosentasche. Wann immer es etwas Neues gibt, klingelt's auf dem Smartphone. Und weil ein Smartphone eben auch ein...
4 MB  
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  
Education  -  A-B-C Learn with me 1.0
Help your children learn their ABC's, their colours, shapes, numbers 1-10, fruit and vegetables, and animals in this collection of simple, fun games, aimed at toddlers 12 months+ From Flashcards to word association and matching pair games...
8.3 MB  
Books  -  A.B.C Mix Up - Do You Know Your Alphabet? 1.3.1
The finale in the I Love ABC series sees the animals and letters all mixed up! Practice what you have learnt in the whole series and match the animals with the appropriate letters in this fun, colorful game! ? Your child will learn:...
44.9 MB  
Games  -  "Bacarba" best Puzzle 1.0
If you love the idea of SuDoku but hate dealing with numbers, Bacarba is most definitely for you. But how can a puzzle involving just three letters be so excruciatingly addictive? Maybe it's because the concept is easier than A, B,...
819.2 KB  
Health & Fitness  -  Vitamins 4 You 1.0.0.0
Every wondered if you are providing all the required nutrients to your body? Wondered how you can improve your overall wellness? Want to learn about essential vitamins, what they do & their food sources? Vitamins (A, B, C, D..) are...
1024 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 3.15.3
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