note
choroba
Move the match with /g into a condition of a while loop.<P>
As there are no capture groups in the regex (i.e. no parentheses), using any other index than 0 makes no sense. Under [doc://warnings], you'd even get lots of <c>Use of uninitialized value in print</c>.<P>
Moreover, when there's no match, the @- and @+ arrays are empty, there's no -1 (that's what [doc://index] does). You have to handle that case yourself.<P>
This should work directly as shown and output the expected output:<P>
<c>
#!/usr/bin/perl
use strict;
use warnings;
my $string = << "__EOS__";
foo bar baz
foo bar foo\tbaz ccc ddd
foo bar foo\tbaz ccc ddd\tfoo\tbar\tbaz
foo bar foo\t\tbaz ccc ddd\t\t\tfoo
__EOS__
open my $F0, '<', \$string or die $!;
while (<$F0>) {
my $match;
while (/\t+/g) {
$match = 1;
print $-[0], ' ', $+[0], ' ';
}
print '-1 -1' unless $match;
print "\n";
}
</c><P>
<!-- Node text goes above. Div tags should contain sig only -->
<div class="pmsig"><div class="pmsig-832495">
<c>map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]</c>
</div></div><!-- Wiki2Monks {"version":1.161} -->
11139917
11139917