I need to find all the files with the same "string"

Group by "string" ⇒ use a hash.

use List::Util qw( min ); my %grouped_maxes; while (<DATA>) { chomp; my ($hash, $amount, $end) = split /_/; push @{ $grouped_maxes{$hash} }, $amount if defined($end) && $end eq 'max'; } for my $hash (keys %grouped_maxes) { print("$hash: ", min( @{ $grouped_maxes{$hash} } ), "\n"); } __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 888aaa222ccc324567fed54333221235_0.21

Additionally I also need to know if there is no _max file at all in the selected files

Keep track of all the unique hash strings you see, keep track of the unique hash strings you see with a max, then remove those with a max from the whole set.

Remove duplicates ⇒ use a hash.

use List::Util qw( min ); my %hashes; my %grouped_maxes; while (<DATA>) { chomp; my ($hash, $amount, $end) = split /_/; ++$hashes{$hash}; push @{ $grouped_maxes{$hash} }, $amount if defined($end) && $end eq 'max'; } for my $hash (keys %hashes) { if (exists($grouped_maxes{$hash})) { my $min_max = min( @{ $grouped_maxes{$hash} } ); print("$hash: $min_max\n"); } else { print("$hash: No max\n"); } } __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 888aaa222ccc324567fed54333221235_0.21
777aaa222ccc324567fed54333221235: 1.04 888aaa222ccc324567fed54333221235: No max 111aaa222ccc324567fed54333221235: 1.02

In reply to Re: File sort and values in file name by ikegami
in thread File sort and values in file name by natol44

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.