ANN: String::Pattern - yet another pattern ( template ) processing module 
Author Message
 ANN: String::Pattern - yet another pattern ( template ) processing module

    String::Pattern - create / identify strings by pattern

            use String::Pattern;
            use strict;

            my $code = "73545-ved-8877";
            my $name = "Benalgin";
            my $prescription = 'X';
            my $price = 10.99;
            my $date;

            my $p = new Pattern 'code: 1223144-x-67 name: Aspirin
prescription: [pr_flag] price: $5.90';
            my $print_view = new Pattern q{
                    record date : 8/11/00
                    code: 1223144-x-67
                    name: Aspirin
                    [pr_flag] prescription
                    price: $5.90

            $p->bind( '1223144-x-67' => \$code);
            $p->bind( Aspirin => \$name);
            $p->bind( '5.90' => \$price, '\d+(?:[,\.]\d{2})?');
            $p->bind( pr_flag => \$prescription);
            $print_view->bind( '8/11/00' => \$date);

            my $q="$p"; # equivalent ot my $q=$p->to_string;

            $prescription=" ";
            my $r = 'code: 1223144x-69 name: Aspirin-Bayer prescription: [ ]
price: $3.124';

            for my $string ($r,     $p,     $q) {
                    print $string, "\n";
                    if ($p->identify($string)) {
                            print "Match on pattern \n";
                            $date = localtime;
                            print $print_view."\n";
                            print "Not match on pattern \n\n"

    This module is designed to deal whith non atomic data strings
    representations whith fixed number of items on it - such as addresses,
    business cards, product descriptors etc. It simplificies string creation
    based on preliminary defined human readable patterns ( templates ) and
    identifying that any given string has format, "described" in the same


    pattern ($string)
        if `$string' is supplied then it will be used as pattern, otherwise
        currently used pattern is returned

    bind ( tag => \$var)
    bind ( tag => \$var, $re)
        binds var ref to specific part of pattern (tag). When string is
        created, all occuriences of that tag will be replaced with the value
        of `$var'. Regular expession `$re' is used to describe what the tag
        looks like, and increases the accuracy of the identify manpage
        method in ambiguous cases. Pattern is used to build one regular
        expession whith backreferences ( for each occurrence of tag ) , so
        brackets usage in `$re' must be only like this (?: ... ).

        Creates string based on pattern and bindings. This method is invoked
        when object ref is evaluated in string context

    identify ($string)
        Returns 1 if `$string' matches on pattern and all occurrences of
        given tag are equal, then sets vars to first occurrence of
        respective bounded tag. Otherwise returns 0 and nothig is changed.

    bind_like ($other_pattern_object)
        Gets bindings from other object. May be useful for copy like
        operations avoiding boring declararions.

                my $p1 = new String::Pattern .....;
                my $p2 = new String::Pattern .....;

                # a lot of bind ...

                # $p2 specific binds

                if ($p1->identify(...)) {
                        print $p2

        so $p2 have all of $p1 bindings plus one additional

  to do

    erros and warnings
        Adding some useful warnings and erros about content of variables,
        and their ralations with tags in the pattern


    perl (1), perlre (3)

Tue, 28 Jan 2003 03:00:00 GMT  
 [ 1 post ] 

 Relevant Pages 

1. yet another pattern matching question...

2. Yet another pattern match question

3. multi-char pattern with other patterns

4. Regular Expressions/Pattern Matching/Unordered pattern

5. How to find pattern in pattern (newbie Q)?

6. pattern as a sentence in pattern matching

7. help with pattern match (repeated patterns)

8. split() INTO pattern instead of ON pattern?

9. newbie perl pattern processing question

10. pattern matching with non-existence of a string

11. Patterns and end-of-string

12. Search pattern from right end of string


Powered by phpBB® Forum Software