in reply to Hash/Array of Regular Expressions?
I use lists of hashes as fast "objects" in parsers a lot. I like compiled regexes in this case, because the way I use them I am putting changed versions in a new slot anyway. To do this I use the quote regex operator, qr//
It gets ugly really fast, though... real OO is "better," except when its too slow, like if you have hundreds of parsers. Though the whole thing could be hidden behind a object, but that's a religious war I'm not qualified to fight; I like it both ways.my @parsers; sub add_parser { my $name = shift; my $re = shift; my %parser = ( name => $name, re => qr/$re/, code => sub { print "Hi, I'm parser $name, who are you?" }, ); push @parsers, \%parser; } add_parser( "HelloWorld", "foo" ); # ... my $find_this = "ffoobar"; foreach my $parser ( @parsers ) { if ( $find_this =~ $parser->{re} ) { &{$parser->{code}}; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Hash/Array of Regular Expressions?
by bikeNomad (Priest) on Jun 24, 2001 at 23:14 UTC | |
by Aighearach (Initiate) on Jun 25, 2001 at 01:01 UTC | |
by bikeNomad (Priest) on Jun 25, 2001 at 01:50 UTC | |
by Aighearach (Initiate) on Jun 25, 2001 at 02:05 UTC |