in reply to puzzled by pos
The problem is that in order for the while loop to finish, there has to be nothing left to match. Try this instead:
But notice that '5' gets skipped. Better than getting caught in an infinite loop i suppose. I still recommend testing for an even lengthed string first. Another consequence is $a is completely destroyed if it is an even number of chars long, and contains the last char if it was odd lengthed.my $a = '12345'; while($a =~ s/(.)(.)//) { my ($b,$c) = ($1,$2); print "$b - $c\n"; }
UPDATE:
Your CB comment is absolutely correct - i was wrong in
assuming that you have to have s/// to solve this one:
while($a =~ /(.)(.)/g){ my ($b,$c) = ($1,$2); print "$b - $c\n"; }
jeffa
L-LL-L--L-LL-L--L-LL-L-- -R--R-RR-R--R-RR-R--R-RR B--B--B--B--B--B--B--B-- H---H---H---H---H---H--- (the triplet paradiddle with high-hat)
|
|---|