RE: Efficiency

2006-04-06 Thread Thomas, Mark - BLS CTR
$last{substr($_,0,4)}=$_ for @myArray; print join \n, sort values %last; Whoops, one thing wrong with this ... since you don't sort before creating your hash, if the order of the data was such that the newer version appears earlier in the array, your results are wrong. Anyway

RE: Efficiency

2006-04-05 Thread Ng, Bill
Okay, Here's what I've come up with: -- @list = (aacs1110, brbt4332, rtxa4320, aacs2000, brig5621, brbt5220, nbvc); @list = sort @list; foreach $item (@list) { $itemPref = substr($item, 0, 4); $itemVers = substr($item, 4); $h{$itemPref} = $itemVers; } foreach $pref

RE: Efficiency

2006-04-05 Thread Wagner, David --- Senior Programmer Analyst --- WGO
[EMAIL PROTECTED] wrote: 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, etcc. The letters portion is a prefix,

RE: Efficiency

2006-04-05 Thread Jerry Kassebaum
For my own amusement and edification, if nothing else: ## @myArray = (aacs1110, brbt4332, rtxa4320, aacs2000, brig5621, brbt5220, nbvc); #I'm using the assumption that the version numbers only increase in time. print @myArray\n\n; while($myArray[$x]) {

RE: Efficiency

2006-04-05 Thread Wagner, David --- Senior Programmer Analyst --- WGO
[EMAIL PROTECTED] wrote: Okay, Here's what I've come up with: -- @list = (aacs1110, brbt4332, rtxa4320, aacs2000, brig5621, brbt5220, nbvc); @list = sort @list; foreach $item (@list) { $itemPref = substr($item, 0, 4); $itemVers = substr($item, 4);

RE: Efficiency

2006-04-05 Thread Steven Manross
@myArray = (aacs1110, brbt4332, rtxa4320, aacs2000, brig5621, brbt5220, nbvc); 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

RE: Efficiency

2006-04-05 Thread Ng, Bill
Subject: RE: Efficiency #!perl use strict; use warnings; my @list = (aacs1110, brbt4332, rtxa4320, aacs2000, brig5621, brbt5220, nbvc); my ($mykey, $mypriorkey) = (q[], q[]); my @finallist = (); foreach $mykey (sort { $a-[1] cmp $b-[1] || $b-[2] = $a-[2

RE: Efficiency

2006-04-05 Thread Wagner, David --- Senior Programmer Analyst --- WGO
@listserv.ActiveState.com Subject: RE: Efficiency #!perl use strict; use warnings; my @list = (aacs1110, brbt4332, rtxa4320, aacs2000, brig5621, brbt5220, nbvc); my ($mykey, $mypriorkey) = (q[], q[]); my @finallist = (); foreach $mykey (sort { $a-[1] cmp $b-[1

RE: Efficiency

2006-04-05 Thread Nelson R. Pardee
Bill, I'm amused you call this efficiency when you said you didn't care about efficiency:-) Of course, it depends on one's definitions... Here are several I came up with, with times for sample data (3 data points): ($pref,$suf)=/(.{4})(.{4})/o; # Time for 3 .294

RE: Efficiency

2006-04-05 Thread Thomas, Mark - BLS CTR
Bill Ng wrote: Okay, Here's what I've come up with: -- @list = (aacs1110, brbt4332, rtxa4320, aacs2000, brig5621, brbt5220, nbvc); @list = sort @list; foreach $item (@list) { $itemPref = substr($item, 0, 4); $itemVers = substr($item, 4); $h{$itemPref} =

RE: Efficiency

2006-04-05 Thread Ng, Bill
- From: Thomas, Mark - BLS CTR [mailto:[EMAIL PROTECTED] Sent: Wednesday, April 05, 2006 5:32 PM To: Ng, Bill; perl-win32-users@listserv.ActiveState.com Subject: RE: Efficiency Here's one: $last{substr($_,0,4)}=$_ for @myArray; print join \n, sort values %last; I'm sure we could reduce