Combining key value pairs from parentheses in Perl
2 answers
If you need all the data, you can first transfer it to a hash.
my %data = $str =~ /\[([^,]+),([^\]]+)\]/g;
use List::Util qw'max';
my($max) = max(values %data);
print "max: $max\n";
If you want to know which key (s) have this number, you can use grep
print "key: $_\n" for grep { $data{$_} == $max } keys %data;
If you really only want the maximum value:
use List::Util qw'max';
print max $str =~ /\[[^,]+,([^\]]+)\]/g;
+5
source to share