tektsu has asked for the wisdom of the Perl Monks concerning the following question:
%apps = ( gcc-3.3 => 1, gcc-3.3.1 => 1, gcc-3.3.2 => 1, gzip-1.2.4a => 1, make-3.79.1 => 1, );
Given an application name, I need to find the latest available version. For example, given the hash above, if I have "gcc", I want to return "gcc-3.3.2", "make" should return "make-3.79.1", and "cobol" should return false or undef.
I can do this by sorting the keys in reverse order and looking for the first match for, for example /^gcc-/, but that seems... inefficient.
I know I will need to get get more creative in my sorting (for example, when gcc-10.0 is released), but for now let's assume that cmp gives a correct comparision between versions.
Any ideas?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Finding the latest available version of a program
by Abigail-II (Bishop) on Feb 02, 2004 at 21:39 UTC | |
|
Re: Finding the latest available version of a program
by paulbort (Hermit) on Feb 02, 2004 at 23:08 UTC | |
|
Re: Finding the latest available version of a program
by saintmike (Vicar) on Feb 02, 2004 at 21:13 UTC | |
|
Re: Finding the latest available version of a program
by ysth (Canon) on Feb 02, 2004 at 21:15 UTC | |
|
Re: Finding the latest available version of a program
by Cody Pendant (Prior) on Feb 03, 2004 at 02:55 UTC | |
|
Re: Finding the latest available version of a program
by elwarren (Priest) on Feb 02, 2004 at 21:50 UTC | |
|
Re: Finding the latest available version of a program
by tektsu (Acolyte) on Feb 03, 2004 at 16:12 UTC |