O
Olof Karlberg
Hi,
I am looking for a way to find the locations of exact substring matches (0.1-3 KB) in a larger string (1-2MB) and was looking at the variables @LAST_MATCH_START and @LAST_MATCH_END (@-/@+) as a solution. The problem is that I just can't get these variables to work the way I thought they should work. As I understand perdoc perlvar on this, the code below _should_ print:
Number of matches: 2
First match begins at: 2
First match ends at: 5
2:nd match begins at: 9
2:nd match ends at: 12
However, what it _does_ print is:
Number of matches: 0
First match begins at: 2
First match ends at: 5
Use of uninitialized value in concatenation (.) or string at ./test.pl line 10.
2:nd match begins at:
Use of uninitialized value in concatenation (.) or string at ./test.pl line 11.
2:nd match ends at:
#!/usr/bin/perl -w
my $target = "QWERTY QWERTY";
my $query = "ERT";
$target =~ m/$query/g;
print "Number of matches: $#-\n";
print "First match begins at: $-[0]\n";
print "First match ends at: $+[0]\n";
print "2:nd match begins at: $-[1]\n";
print "2:nd match ends at: $+[1]\n";
What is going on here? Have I totally misunderstood the docs?
The above is the result from Perl 5.8.0 on a new Gentoo Linux system (gcc version 3.2.2). The same code on Perl 5.6.1 on Suse 8.0 (gcc version 2.95.3) gives the same printout as above with the following diff:
Number of matches: 2020961897
Anyone else seen this behaviour?
//Olof
I am looking for a way to find the locations of exact substring matches (0.1-3 KB) in a larger string (1-2MB) and was looking at the variables @LAST_MATCH_START and @LAST_MATCH_END (@-/@+) as a solution. The problem is that I just can't get these variables to work the way I thought they should work. As I understand perdoc perlvar on this, the code below _should_ print:
Number of matches: 2
First match begins at: 2
First match ends at: 5
2:nd match begins at: 9
2:nd match ends at: 12
However, what it _does_ print is:
Number of matches: 0
First match begins at: 2
First match ends at: 5
Use of uninitialized value in concatenation (.) or string at ./test.pl line 10.
2:nd match begins at:
Use of uninitialized value in concatenation (.) or string at ./test.pl line 11.
2:nd match ends at:
#!/usr/bin/perl -w
my $target = "QWERTY QWERTY";
my $query = "ERT";
$target =~ m/$query/g;
print "Number of matches: $#-\n";
print "First match begins at: $-[0]\n";
print "First match ends at: $+[0]\n";
print "2:nd match begins at: $-[1]\n";
print "2:nd match ends at: $+[1]\n";
What is going on here? Have I totally misunderstood the docs?
The above is the result from Perl 5.8.0 on a new Gentoo Linux system (gcc version 3.2.2). The same code on Perl 5.6.1 on Suse 8.0 (gcc version 2.95.3) gives the same printout as above with the following diff:
Number of matches: 2020961897
Anyone else seen this behaviour?
//Olof