in reply to Re^3: Efficient regex matching with qr//; Can I do better?
in thread Efficient regex matching with qr//; Can I do better?
The idea of using an array and specify indexes I didn't really understand the benefit of at first glance.The idea is to eliminate as much code as possible specifically from the parts that run for each pattern and each text string. This means this bit:
Which, for each iteration, does this:while (my($text_id,$text) = each(%hash2) ) { if ($text =~ $match)
If the text strings are unique, such that you can determine the $text_id given $text, you can leave out the array stuff and just do this:
Because for (@array) doesn't copy array but just iterates over it, and $text is aliased to each element in turn, not copied over it, this should be faster.my @text = values %hash2; my %reverse_hash2 = reverse %hash2; while ( my($pattern,$high_lvl_id) = each(%hash1) ) { my $match = qr/\b$pattern\b/; for my $text (@text) { if ( $text =~ $match ) { my $text_id = $reverese_hash2{$text}; ... } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Efficient regex matching with qr//; Can I do better?
by kruppy (Initiate) on Jul 14, 2008 at 05:46 UTC | |
by ysth (Canon) on Jul 14, 2008 at 05:49 UTC |