On Tue, Nov 30, 1999 at 04:10:20PM +0000, Ralph Corderoy wrote: > > Hi, > > Assigning a /gx regexp to a list breaks \G in the following regexp. > > #! /usr/local/bin/perl -w > > $_ = 'a 1 b 2 c 3'; > > print "bug\n"; > ($a, $b) = /^(\w)\s(\d)\s/gx; > print "a=$a b=$b\n"; > ($a, $b) = /\G(\w)\s(\d)/gx; > print "a=$a b=$b\n"; > > print "workaround\n"; > /^(\w)\s(\d)\s/gx; > ($a, $b) = ($1, $2); > print "a=$a b=$b\n"; > ($a, $b) = /\G(\w)\s(\d)/gx; > print "a=$a b=$b\n"; > > Output is > > bug > a=a b=1 > a=a b=1 > workaround > a=a b=1 > a=b b=2 > This is the expected behavior for m//g in a list context. The regular expression is applied repeatedly until it no longer matches, and the return value is a list of all the substrings matched. After the final application of the regex, which fails to match, pos() is reset to the beginning of the string. Try this instead: #! /usr/local/bin/perl -w $_ = 'a 1 b 2 c 3'; @a = /\G(\w)\s(\d)\s?/gx; $" = ','; print "@a\n"; Output: a,1,b,2,c,3 RonaldThread Previous | Thread Next