in reply to Capturing with look-ahead

I suspect that this question is related to the current Perl Review golfing challenge, but here is a solution to your problem. I could give you a regex-based solution but it would be more complicated and probably less efficient.

#!/usr/local/bin/perl -w use strict; my @x; $_="blah"; for my $i (0..length($_)-2) { $x[$i]=substr($_,$i,1).substr($_,$i+1,1); } print "@x\n";
produces...
bl la ah

metadoktor

"The doktor is in."

  • Comment on Grabbing Adjacent Chars In A String - Re: Capturing with look-ahead
  • Download Code