more useful options | |
PerlMonks |
printing LAST_MATCH_START/@- LAST_MATCH_END/@+ array where regex match begin/endby perl_boy (Novice) |
on Dec 26, 2021 at 20:48 UTC ( [id://11139917]=perlquestion: print w/replies, xml ) | Need Help?? |
perl_boy has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying to print the content of the array that contains the indexes/positions before and after {LAST_MATCH_START/@- LAST_MATCH_END/@+} where the /\t+/ regex matched within the read input string $_ for example the following input file foo bar baz foo bar foo baz ccc ddd foo bar foo baz ccc ddd foo bar baz foo bar foo baz ccc ddd fooshould print -1 -1 11 12 11 12 23 24 27 28 31 32 11 13 24 27that is 0 based positions where TABs \t occur in the input file each TAB having a begin end position NOTE:
line 2 prints "11 12" TABs \t as this is the 0 base index/position of the start/end of the only TAB \t on that line line 3 prints "11 12 23 24 27 28 31 32" as this is the 0 base indexes/positions of the start/end of the 4 TABs \t on that line line 3 have one adjecsent TABs,that is,there is only 1 TAB between words foo and baz,ddd and foo,foo and bar,bar and baz line 4 prints "11 13 24 27" as this is the 0 base indexes/positions of the start/end of the 4 TABs \t on that line line 4 have more than 1 {>1 >=2} one adjecsent TABs,that is,there is more than 1 {>1 >=2} one TABs between words foo and baz,ddd and foo,foo and bar,bar and baz 11 12 11 12 11 13NOTE:
11 12 31 32 37 42 NOTE:
where the regex matched within the read input string $_ using $-[] and $+[] (lines 6 and 7) here is the code NOTE:
I then searched google "perl regex LAST_MATCH_START/@- LAST_MATCH_END/@+ bug" and found https://github.com/Perl/perl5/issues/16109 that says its not a bug It would be very helpful if someone could explain what's going on and how to print the right indexes/positions where TAB \t occurs thank's
Back to
Seekers of Perl Wisdom
|
|