removing deplicate entries based on first column and keeping the latest entry, using Perl -


i need perl code following problem. in advance efforts.

my input in file in format: 'name' 'version number'


tech-sgla-zustand-ts.ini    1.1 tech-sgla-zustand-ts-feld.ini    1.1 tech-sgla-stamm-cds-feld.ini    1.1 tech-sgla-zustand-ts-feld.ini    1.2 tech-sgla-zustand-ts-feld.ini    1.4 tech-sgla-zustand-ts-feld.ini    1.3 

i need in format (without blank lines in between): 'name' should unique maximum 'version number'


tech-sgla-zustand-ts.ini    1.1 tech-sgla-zustand-ts-feld.ini    1.4 tech-sgla-stamm-cds-feld.ini    1.1 

you use :

my %inifiles = (); while (<>) {   ($ini, $vers) = split / +/, $_;   if (exists $inifiles{$ini}) {     $inifiles{$ini} = $vers if ($inifiles{$ini} < $vers);   } else { $inifiles{$ini} = $vers } } while (my ($k,$v) = each %inifiles) { print "$k $v\n" } 

or if input order important :

my @inis = (); %inifiles = (); while (<>) {   ($ini, $vers) = split / +/, $_;   if (exists $inifiles{$ini}) {     $inifiles{$ini} = $vers if ($inifiles{$ini} < $vers);   } else { push @inis, $ini; $inifiles{$ini} = $vers } } foreach (@inis) { print "$_ $inifiles{$_}\n" } 

Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -