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			foo
should print
-1 -1
11 12
11 12 23 24 27 28 31 32
11 13 24 27
that is 0 based positions where TABs \t occur in the input file each TAB having a begin end position

NOTE:
    line 1 print "-1" as there are no TABs \t
    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
but prints when I uncomment line 4 /\t+/g;
11
12
11
12
11
13
NOTE:
    2 empty lines (1 and 2) begin-of-file it only print that first start/end TAB index/position the start ($-*) and end ($+*) are printed on 2 lines
and when I uncomment line 5 s/\t+/9/g;

11 12 31 32 37 42

NOTE:
    2 empty lines (1 and 2) begin-of-file it only print that last start/end TAB index/position the start ($-*) and end ($+*) are printed on 2 lines
I'm trying to print the content of the LAST_MATCH_START/@- and LAST_MATCH_END/@+ array that contains the indexes/positions
where the regex matched within the read input string $_ using $-[] and $+[] (lines 6 and 7)
here is the code
open(F0, $ARGV[0]); while(<F0>) { # /\t+/g; # s/\t+/9/g; print $-[0], " ",$-[1], " ", $-[2], "\n" ; print $+[0], " ",$+[1], " ", $+[2], "\n" ; } close F0;
NOTE:
    I used g modifier at the end of the regexes (lines 4 and 5)
this is really strange as the /\t+/g; prints the first and s/\t+/9/g; prints the last
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

In reply to printing LAST_MATCH_START/@- LAST_MATCH_END/@+ array where regex match begin/end by perl_boy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.