On 5/25/05, Jeff 'japhy' Pinyan <[EMAIL PROTECTED]> wrote: > On May 25, Jay Savage said: > > > /e(?{push @bar, pos})/g; > > > > should work, but seems to ignore the /g. > > Because as you wrote it, the regex is in void context, which means it'll > only match once. Put it in list context: > > () = /e(?{ push @bar, pos })/g; > > But this looks weird to almost anyone. I'd do: > > /e(?{ push @bar, pos })(?!)/;
Thanks. this makes sense. But why does the zero-width lookahead force list context? And why does /g by itself force list context for s/// with the same search string? > > If 'e' is more than one character, you'll need to use > > /(?>pattern)(?{ push @bar, pos })(?!)/; Assuming that the patter to matc on = "pattern", this works, too: /p(?:{push @bar, pos})attern(?!)/g > > You could also use $-[0] instead of pos(). > That depends on the context. $-[0] holds the value of the beginning of the current match. pos() returns the position at the end of the current match, i.e. $+[0], and is what the OP used. $-[0] = pos() - length($&), more or less. For single-character matches, this has the effect of making values returned from $-[0] zero indexed, and values returned from pos() one indexed. (That's also why any (?{}) expression with pos needs to be inserted after the frist character of a multi-character match.) --jay -------------------- daggerquill [at] gmail [dot] com http://www.engatiki.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>