First of all, you should put the text returned by backticks imp_val ...in an array instead of a scalar. This will divide it into lines and simplify management.
, map . . , Data::Dump dd , :
use strict;
use warnings;
use Data::Dump;
my @retval = `imp_vol -u 110.5 -s 110.9 -p 0.005 -t 0.041 -c 1`;
my %scholes = map { /(\w+)\s*=\s*(-?[\d.]+)/ } @retval;
dd \%scholes;
, ,
{
Delta => 0.049565,
Gamma => 0.42329,
NDelta => 0.0494522,
NGamma => 0.42176,
NTheta => -0.302207,
NVega => 0.0207006,
NVol => 1.19711,
Theta => -0.302212,
Vega => 2.29159,
Vol => 0.0108141,
}
, , . , :
use strict;
use warnings;
use Data::Dump;
sub scholes {
my @retval=`imp_vol -u 110.5 -s 110.9 -p 0.005 -t 0.041 -c 1`;
my %scholes = map { /(\w+)\s*=\s*(-?[\d.]+)/ } @retval;
return @scholes{qw/ Vol Delta Gamma Theta Vega NVol NDelta NGamma NTheta NVega /};
}
dd [ scholes ];
[
0.0108141,
0.049565,
0.42329,
-0.302212,
2.29159,
1.19711,
-0.302207,
0.0207006,
0.0494522,
0.42176,
]