Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (3)
As of 2024-04-24 01:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found