G
Graham Drabble
I have the following data in a file
p p p p p p p p
p b b p p p p p
b b p p p p p
s b b p p p p p
p b b p b b p p
s b p p p p p p
s b b b p p p p
p b b b b b p p
b b p b p p p
b b b b p p p
p p p p p b b
p s b s p p p b
I'm looking to write a regular expression that will only match if a
'b ' are paired together.
I've currently got
use strict;
use warnings;
open IN, '<', 'pb.txt' or die "Can't open IN: $!";
while (<IN>){
chomp;
my $regex;
if (!/[sp] b [sp]/){
$regex = 1;
}else{
$regex = 0;
}
print "$_\t $regex\n";
}
which produces
p p p p p p p p 1
p b b p p p p p 1
b b p p p p p 1
s b b p p p p p 1
p b b p b b p p 1
s b p p p p p p 0
s b b b p p p p 1
p b b b b b p p 1
b b p b p p p 0
b b b b p p p 1
p p p p p b b 1
p s b s p p p b 0
It should (if it was doing what I wanted!) produce
p p p p p p p p 1
p b b p p p p p 1
b b p p p p p 1
s b b p p p p p 1
p b b p b b p p 1
s b p p p p p p 0
s b b b p p p p 0 ****
p b b b b b p p 0 ****
b b p b p p p 0
b b b b p p p 1
p p p p p b b 1
p s b s p p p b 0
(The **** are not output but are there to indicate the lines that it
gets wrong.)
The problem is that it treats 'b b b' as good where it shouldn't
(although b b b b is fine).
Any suggestions?
p p p p p p p p
p b b p p p p p
b b p p p p p
s b b p p p p p
p b b p b b p p
s b p p p p p p
s b b b p p p p
p b b b b b p p
b b p b p p p
b b b b p p p
p p p p p b b
p s b s p p p b
I'm looking to write a regular expression that will only match if a
'b ' are paired together.
I've currently got
use strict;
use warnings;
open IN, '<', 'pb.txt' or die "Can't open IN: $!";
while (<IN>){
chomp;
my $regex;
if (!/[sp] b [sp]/){
$regex = 1;
}else{
$regex = 0;
}
print "$_\t $regex\n";
}
which produces
p p p p p p p p 1
p b b p p p p p 1
b b p p p p p 1
s b b p p p p p 1
p b b p b b p p 1
s b p p p p p p 0
s b b b p p p p 1
p b b b b b p p 1
b b p b p p p 0
b b b b p p p 1
p p p p p b b 1
p s b s p p p b 0
It should (if it was doing what I wanted!) produce
p p p p p p p p 1
p b b p p p p p 1
b b p p p p p 1
s b b p p p p p 1
p b b p b b p p 1
s b p p p p p p 0
s b b b p p p p 0 ****
p b b b b b p p 0 ****
b b p b p p p 0
b b b b p p p 1
p p p p p b b 1
p s b s p p p b 0
(The **** are not output but are there to indicate the lines that it
gets wrong.)
The problem is that it treats 'b b b' as good where it shouldn't
(although b b b b is fine).
Any suggestions?