Following is the script for matching regex and storing value in array:
sub b1 {
# print $_;
my @file = @_;
my @value;
my $find = qr/(\s+)([0-9]+)\s([A-Z])\s[0-1].[0-9]+\s->\s([A-Z])\s/;
foreach my $file(@file){
push (@value, $file=~ /$find/) ;
print "\n";
}
return @value;
}
my @array_b1 = b1(@body);
print "@array_b1 \n";
__DATA__
28 C 0.510 -> L 0.923
30 S 0.638 -> A 0.527
31 A 0.496 -> P 0.952
__OUTPUT__
28 C L 30 S A 31 A P
While capturing values from regex and storing it an array, the script stores values in consecutive elements in array i.e. the above array has elements:
@array[1]=28
@array[2]=C
@array[3]=L
@array[4]=30.
Instead, I want to store values captured by the regex in same array element. That is:
@array[1]=28CL
@array[2]=30SA
What is the best way to do that?