Ronald J Kimball wrote:

> m//g only sets pos() when it's in scalar context.  I don't think pos()
> would generally be useful after a match in list context.

argh. That's exactly how I want to use it. I have a subroutine that
receives a pattern and then does a regexp with the pattern.
it doesn't know if the pattern contains parens, so I wanted to capture
the results using list context and just pass the array back.

unfortunately, $1, $2, $3, etc, is not exactly easy to code in a generic
way.
there doesn't happen to be a global array that corresponds to:
        @GLOBAL::MATCHES($1, $2, $3, $4, $5, $6, ...);

or some such thing? would I be that lucky?
hey, can we slide this into perl6 if it isn't in there now?

> Note that your second example actually prints whatever pos() was set to
> before the match in list context; the list context match doesn't affect
> pos() at all.

???

I get undef on the second example:

my $hstr1 = "fee fie foe foo";
$hstr1 =~ m/e/mcg;
print "position is ".pos($hstr1)."\n";

my $hstr2 = "fee fie foe foo";
my @matches = $hstr2 =~ m/e/mcg;
print "position is ".pos($hstr2)."\n";

gives me this output:

position is 2
Use of uninitialized value in concatenation (.) at .//junk.pl line 11.
position is 


-- 
Greg London
x7541

Reply via email to