@myArray = ("aacs1110", "brbt4332", "rtxa4320", "aacs2000", "brig5621",
"brbt5220", "nbvc1111");
foreach $data (@myArray) {
  $data =~ /(....)(....)/;
  if ($hash{$1} < $2) {
    $hash{$1} = $2;
  }
}

foreach $key (keys %hash) {
  print $key ." = ".$hash{$key}."\n";
}
 
Seems to work...

Steven

> -----Original Message-----
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On 
> Behalf Of Ng, Bill
> Sent: Wednesday, April 05, 2006 12:19 PM
> To: perl-win32-users@listserv.ActiveState.com
> Subject: Efficiency
> 
> Since Efficiency seems to be the topic of the day,
> 
>       My situation, I have an array filled with 8-character 
> strings, a few thousand of them.  First 4 chars are letters, 
> last 4 are numbers.
> Examples - abcd1234, zyxw9876, etcc2222.  The letters portion 
> is a prefix, the numbers is a version.  In my list, there are 
> instances of the same prefix with different versions.
> 
>       What's the easiest way for me to either clean up the 
> existing array to remove all but the latest versions of each 
> prefix, or create a new array with the same info?  Focus is 
> on least amount of code, I'm not going for outright speed.  
> No modules.  I've got it working now but I'm running nested 
> foreach loops and an if statement ... not efficient at all.
> 
> Example:
> ------------
> @myArray = ("aacs1110", "brbt4332", "rtxa4320", "aacs2000", 
> "brig5621", "brbt5220", "nbvc1111")
> ------------
> The code would give me an array that contained everything 
> except aacs1110 & brbt4332 since both have been superseded.
> 
> Bill
> 
> _______________________________________________
> Perl-Win32-Users mailing list
> Perl-Win32-Users@listserv.ActiveState.com
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
> 
> 

_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to