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