in reply to search pattern with digits
I gather that your search phrase will be determined at run time, and not only the phrase, but also whether the data comes before or after the phrase.
How is your program going to be notified of the search phrase? Is there some way it can also be notified of the positioning of the numerical data?
If you have any control over the earlier stage where the search phrase is identified, ask to have the search phrase specified as a regular expression complete with capturing parentheses.
sub capture_numbers { my ( $search_phrase ) = @_; croak "Search phrase $search_phrase lacks capturing parentheses" if $search_phrase !~ /\(/; my @results; while <LOG_FILE> { my ( $desired_number ) = /$search_phrase/o; push @results, $desired_number; } }
This sub accepts either of your two example search phrases with their differing syntax:
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: search pattern with digits
by mercuryshipz (Acolyte) on Feb 14, 2008 at 22:31 UTC | |
by Narveson (Chaplain) on Feb 15, 2008 at 09:47 UTC | |
by mercuryshipz (Acolyte) on Feb 15, 2008 at 16:23 UTC |