I am searching for a string in Perl and storing it in another scalar variable. I want to print this scalar variable. The code below doesn\'t seem to work. I am not sure what is
JB is correct. Your regular expression would need to use captures (which are defined by parentheses) for the individual parts to be collected. If you want to capture all of the elements in your line, you would want this:
my $find = '\s{10}([0-9]{2})\s([A-Z])';
my $field1;
my $field2;
while (my $line = ) {
chomp ($line);
if ($line=~ /$find/) {
$field1 = $1;
$field2 = $2;
# Do something with current line's field 1 and field 2
}
}