Presumably the search result will be a complete record, or a partial record. Do the record separation on input rather than in each regex search.
The records could be stored as an array of stings (simple @record_as_string) where each element is one string representing the whole record. Or an Array of Hash (AoH) - that's what TJPride did (or close) instead of the print, just: push @AoH, \%data;
I think its appropriate to mention than in addition to re-defining the input record separator to be "Name:", you can also set it($/) to undef. If you do that then the entire file can be "slurped" into one variable without doing all the concatenate stuff. But I don't think that is what you need.
I also really doubt that you are going to run into a memory problem. A 10MB file in the format that you have would be no problem at all - and would have a LOT of addresses! There are ways to solve any "memory problem", but I don't think that memory is even close to being an issue according to your description. If the data set is a 100MB file, the we probably ought to talk more.my $all_data; { local $/ = undef; #no separator means whole file $all_data = <DATA>; } # now $/ is back to what it was before # that is what the local within a lexical scope did
If you are familiar with 'C', the Perl Array of Hash, is very similar to the 'C' Array of Structure. Lots of streets are named after people. Geez, how many "Martin Luther King" boulevards are there? If you go this way, it will be easier to "fine tune" your search regex'es to the data that is relevant.
There are two great parsing techniques. Both are fine.
If you need help on searching the array structure (however you choose to do it), ask again.
In reply to Re: proper way of matching multiple line patterns
by Marshall
in thread proper way of matching multiple line patterns
by perlperlperl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |