Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^3: convert string into a match pattern

by dave_the_m (Monsignor)
on Dec 22, 2017 at 04:05 UTC ( #1206018=note: print w/replies, xml ) Need Help??


in reply to Re^2: convert string into a match pattern
in thread convert string into a match pattern

is there a simlple possibility to get also the string in index in case of a match
Not that I can immediately think of. Less simple techniques depend on whether you expect most lines to match at least one of the strings, or for most lines to be rejected. If the latter, then you can use my suggested join'|' technique to quickly reject most lines, then use a slower technique only on the matching lines to find which string matched. For example you could generate a second pattern which includes captures, e.g. /(string1)|(string2)|..../ and apply it to matched lines, then see what is the first non-undef value out of $-[1], $-[2], .., $-[N]. This pattern is less efficient than /string1|string2|.../ as it isn't internally compiled into a trie and thus has to check every string in in turn, which is slow for many strings.

Dave.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1206018]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2019-07-23 05:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If you were the first to set foot on the Moon, what would be your epigram?






    Results (24 votes). Check out past polls.

    Notices?