in reply to Help with regex, how to get the largest integer in a string?

This uses a descending numerical sort and grabs the first element to get the largest integer. It also keeps the associated text that goes before the integer.

my $rxPair = qr{(?x) ( [A-Z]+ \s+ \d+ ) }; print map { qq{$_->[0]\n @{ $_->[1] }\n} } map { my $raLine = $_; my $raMax = ( sort {$b->[1] <=> $a->[1] } @{ $raLine->[1] } )[0]; [ $raLine->[0], $raMax ] } map { chomp; [ $_, [ map { [ split ] } m{$rxPair}g ] ] } <DATA>; __END__ ASBSDEC 34 GADVVEEVEETTE 56 IOEOREAK GKJEOG EFEAF 1090 DAFFEE 376 ASB C 134 PPKOREAK EFEAF 290 BLAH 99 BLAH 123 FRED 27 BARNEY 427

Here's the output

ASBSDEC 34 GADVVEEVEETTE 56 IOEOREAK GKJEOG EFEAF 1090 DAFFEE 376 EFEAF 1090 ASB C 134 PPKOREAK EFEAF 290 EFEAF 290 BLAH 99 BLAH 123 FRED 27 BARNEY 427 BARNEY 427

A little late but never mind.

Cheers,

JohnGG