The stupid question is the question not asked | |
PerlMonks |
Re: printing LAST_MATCH_START/@- LAST_MATCH_END/@+ array where regex match begin/endby choroba (Cardinal) |
on Dec 26, 2021 at 21:26 UTC ( [id://11139918]=note: print w/replies, xml ) | Need Help?? |
Move the match with /g into a condition of a while loop. As there are no capture groups in the regex (i.e. no parentheses), using any other index than 0 makes no sense. Under warnings, you'd even get lots of Use of uninitialized value in print. Moreover, when there's no match, the @- and @+ arrays are empty, there's no -1 (that's what index does). You have to handle that case yourself. This should work directly as shown and output the expected output:
map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
In Section
Seekers of Perl Wisdom
|
|