j proctor wrote:
>
> > hm, I couldn't find @- or @+ in the second edition of Programming Perl.
> > when you get some docs handy, could you point me to a specific source?
>
> They hold the offsets of the beginnings and ends of the last successful
> submatches. $-[0] is the offset of the beginning of the entire match,
> $+[0] the offset of the end of the entire match.
>
ah $#!+
talk about inconsistency.
perl can't seem to get both right at the same time.
the following code samples what
I've been trying to do.
in the first example (first set of curly braces),
$-[-1] gives me the correct pos, but
pos() gives me undef.
in the second example
pos() gives me the correct position, but
$-[-1] gives me undef.
cripes!
Greg
#!/usr/local/bin/perl -w
use strict;
{
package global_pos_works_but_pos_func_doesnt;
my $str = 'module abc module xyz module qrs';
my @matches = $str =~ m/module (\w+)/gc;
foreach my $match (@matches)
{
print "match is $match \n";
}
my $pos = pos($str);
print "pos is $pos \n";
my $global_pos = $+[-1];
print "global_pos is $global_pos \n";
}
print "BREAK \n";
{
package pos_func_works_but_global_doesnt;
my $str = 'module abc module xyz module qrs';
my @matches;
while($str =~ m/module (\w+)/gc)
{
push(@matches, $1);
}
foreach my $match (@matches)
{
print "match is $match \n";
}
my $pos = pos($str);
print "pos is $pos \n";
my $global_pos = $+[-1];
print "global_pos is $global_pos \n";
}