$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
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
[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,
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]) {
[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);
@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
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
@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
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
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} =
-
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
11 matches
Mail list logo