$\ = "\n";
$, = ",";
print 'a string' =~ m/(.(?{pos()+=4}))/g;
__END__
prints "a, ,s,t,r,i,n,g". It should print "a,i"
####
'14567890ab' =~
m/(.(?{$char = substr($_,pos(),1);
print "> ".pos()." \"$char\" ";
if ($char eq '4' or
$char eq '6' or
$char eq '8')
{
print "+".(0+$char)." ";
pos() += 0+$char;
}
else
{
print '+0 ';
}
printf "< %2d \"". substr($_,pos(),1)."\" ", pos();
})
(?{printf "-> %2d\n", pos}))+/x;
__DATA__
> 1 "4" +4 < 5 "8" -> 1 # alter pos()
> 2 "5" +0 < 2 "5" -> 2
> 3 "6" +6 < 9 "b" -> 3 # alter pos()
> 4 "7" +0 < 4 "7" -> 4
> 5 "8" +8 < 10 "" -> 5 # alter pos()
> 6 "9" +0 < 6 "9" -> 6
> 7 "0" +0 < 7 "0" -> 7
> 8 "a" +0 < 8 "a" -> 8
> 9 "b" +0 < 9 "b" -> 9
> 10 "" +0 < 10 "" -> 10
####
__SIG__
use B;
printf "You are here %08x\n", unpack "L!", unpack "P4", pack
"L!", B::svref_2object(sub{})->OUTSIDE;