P
Peng Yu
Hi,
I have the following code and output. I'm not sure why the code
doesn't search for 'abc' in the second string 'efgabcabcd'. Could you
anybody let me know what the problem is and how to fix it?
$ cat main.pl
#!/usr/bin/env perl
use strict;
use warnings;
my @strings=('abcdefgabc', 'efgabcabcd');
my $pattern='abc';
foreach my $s (@strings) {
my @offsets=();
{
use re 'eval';
$s =~ /(?=\Q$pattern\E)(??{push @offsets, $-[0]})/g;
}
print join('::', @offsets), "\n"
}
print "end\n";
$ ./main.pl
0::7
end
I have the following code and output. I'm not sure why the code
doesn't search for 'abc' in the second string 'efgabcabcd'. Could you
anybody let me know what the problem is and how to fix it?
$ cat main.pl
#!/usr/bin/env perl
use strict;
use warnings;
my @strings=('abcdefgabc', 'efgabcabcd');
my $pattern='abc';
foreach my $s (@strings) {
my @offsets=();
{
use re 'eval';
$s =~ /(?=\Q$pattern\E)(??{push @offsets, $-[0]})/g;
}
print join('::', @offsets), "\n"
}
print "end\n";
$ ./main.pl
0::7
end