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

Array::PatternMatcher 0.04

  Date Added: October 23, 2010  |  Visits: 667

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
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  
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  -  A-B-C Learner 1.0
"A-B-C Learner" apps is fun and learn based app for kids. identify words and explode balloons in a sequence which can help kids to remember words and increase IQ level. "A-B-C Learner" is like having preschool right on your...
3 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  
NEW DOWNLOADS IN PROGRAMMING, LIBRARIES
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 freedesktop.org, 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  -  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  
Libraries  -  App::SimpleScan::Substitution::Line 2.02
App::SimpleScan::Substitution::Line is a line with optional fixed variable values. SYNOPSIS my $line = App::SimpleScan::Substitution::Line->new(" this "); # Use only this value when substituting " ". $line->fix(substituite =>...
54.27 KB