when run, givesuse warnings; use strict; use Data::Dumper; my @files = <DATA>; chomp @files; warn Dumper \@files; sub get_least($) { my $md5 = shift; my $num = ( sort map { s/${md5}_//; s/_max//; ($_) } grep /^$md5.*_max/, @ +files )[0]; warn("No max file"), return undef unless $num; return $num; } warn get_least(q/111aaa222ccc324567fed54333221235/); warn get_least(q/777aaa222ccc324567fed54333221235/); warn get_least(q/99999999999999999999999999999999/); __DATA__ 111aaa222ccc324567fed54333221235_1.04 111aaa222ccc324567fed54333221235_1.05_max 111aaa222ccc324567fed54333221235_0.98_min 111aaa222ccc324567fed54333221235_1.02_max 111aaa222ccc324567fed54333221235_0.21 777aaa222ccc324567fed54333221235_1.04 777aaa222ccc324567fed54333221235_1.07_min 777aaa222ccc324567fed54333221235_1.04_max 99999999999999999999999999999999_1.04 99999999999999999999999999999999_1.07_min 99999999999999999999999999999999_1.04_min
which, I believe, is as required.$ perl tst.pl $VAR1 = [ '111aaa222ccc324567fed54333221235_1.04', '111aaa222ccc324567fed54333221235_1.05_max', '111aaa222ccc324567fed54333221235_0.98_min', '111aaa222ccc324567fed54333221235_1.02_max', '111aaa222ccc324567fed54333221235_0.21', '777aaa222ccc324567fed54333221235_1.04', '777aaa222ccc324567fed54333221235_1.07_min', '777aaa222ccc324567fed54333221235_1.04_max', '99999999999999999999999999999999_1.04', '99999999999999999999999999999999_1.07_min', '99999999999999999999999999999999_1.04_min' ]; 1.02 at tst.pl line 22, <DATA> line 11. 1.04 at tst.pl line 23, <DATA> line 11. No max file at tst.pl line 18, <DATA> line 11. Use of uninitialized value in warn at tst.pl line 24, <DATA> line 11. Warning: something's wrong at tst.pl line 24, <DATA> line 11.
In reply to Re: File sort and values in file name
by Bloodnok
in thread File sort and values in file name
by natol44
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |