justin423 has asked for the wisdom of the Perl Monks concerning the following question:
I want to match a regex only once in a long file of data.
The regex is this:
{foreach my $line (@lines) { if ($line=~ m/<FILENAME>.*\.htm/) {$doc_title_temp=substr $line, 10;$ +doc_title=$doc_title_temp;print "Filename is $doc_title"};
But in one of the documents I was searching, it had this in there and it was matching on both, and assigning the variable value twice, so it ended up with the 2nd value
https://www.sec.gov/Archives/edgar/data/831001/000095010323011632/0000950103-23-011632.txt
<FILENAME>dp198076_424b2-us2342673.htm
<FILENAME>dp198076_exfilingfees.htm
I always want to match on the first, so the only logic I need is to just match one time in the long file and not match again.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: pattern matching once
by Marshall (Canon) on Aug 11, 2023 at 03:44 UTC | |
Re: pattern matching once
by eyepopslikeamosquito (Archbishop) on Aug 11, 2023 at 07:36 UTC | |
by justin423 (Scribe) on Aug 11, 2023 at 13:33 UTC | |
by eyepopslikeamosquito (Archbishop) on Aug 11, 2023 at 14:24 UTC | |
| |
by Marshall (Canon) on Aug 11, 2023 at 16:50 UTC | |
by justin423 (Scribe) on Aug 11, 2023 at 16:58 UTC | |
by Marshall (Canon) on Aug 11, 2023 at 19:45 UTC | |
| |
Re: pattern matching once
by karlgoethebier (Abbot) on Aug 11, 2023 at 18:40 UTC | |
Re: pattern matching once
by jwkrahn (Abbot) on Aug 11, 2023 at 03:57 UTC | |
by jo37 (Curate) on Aug 11, 2023 at 09:30 UTC | |
by jwkrahn (Abbot) on Aug 11, 2023 at 17:27 UTC | |
by haukex (Archbishop) on Aug 11, 2023 at 17:42 UTC | |
by jwkrahn (Abbot) on Aug 11, 2023 at 20:03 UTC | |
by haj (Vicar) on Aug 11, 2023 at 17:45 UTC | |
by choroba (Cardinal) on Aug 12, 2023 at 18:40 UTC | |
Re: pattern matching once
by AnomalousMonk (Archbishop) on Aug 11, 2023 at 19:37 UTC |