I am working with the following data:
__DATA__
Branch 1: 10..11
13 E 0.496 -> Q 0.724
18 S 0.507 -> R 0.513
19 N 0.485 -> S 0.681
Branch 2: 11..12
81 R 0.891 -> Q 0.639
88 Y 0.987 -> S 0.836
From the above data, I want to read numbers present before a character and then print them out. So for instance in Branch 1 I want to read 13 , 18, 19 and from Branch 2, I want to read 81 88.
I have written the following code for reading Branch 1 but it doesn't seem to work. Any suggestions?
#!/usr/bin/perl
use strict;
use warnings;
my $find = 'Branch 1:';
$a = '0';
open (FILE, "/user/Desktop/file") || die "can't open file \n";
while (my $body = <FILE>) {
if ($body =~ m/$find/) {
my $value = my $body=~ m/\d{2}\s[A-Z]/;
print "$value \n";
}
else {
$a++; # only to check it reading anything
print "$a \n";
}
}
__END__