473,385 Members | 1,279 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Sorting a list by Secondary Key

Hi everyone,

I have not touched Perl in the last 4 years, my books are at work and I have something here I'm struggling to figure out. From a known list of servers, I need to gather up how many clearcase views are on each server and then only choose the one that has the least number of views that given day. This is what I have so far.

my @servers = qw (
srv30bld4
srv30bld5
srv40bld2
srv40bld3
srv40bld4
);
foreach (@servers) {
my @view = `$CT lsview -short -host $_ | wc -l`;

I'm running the clearcase command "lsview" on each server and doing a wc so I know just how many views came back. The result I get is as follows.

srv30bld4 92
srv30bld5 0
srv40bld2 58
srv40bld3 3
srv40bld4 2

So now I know how many clearcase views are on each server but I only want the one with the lowest amount. I'm having difficulty sorting this list. Any help is appreciated.

Thanks.
Mar 17 '07 #1
3 1667
KevinADC
4,059 Expert 2GB
assuming @view is what needs sorting:

Expand|Select|Wrap|Line Numbers
  1. @view = ('srv30bld4 92','srv30bld5 0','srv40bld2 58','srv40bld3 3','srv40bld4 2');
  2. @view = map {$_->[0]} sort {$a->[1] <=> $b->[1]} map {chomp;[$_, /\s+(\d+)$/]} @view;
  3. print $view[0];
but what if there are two or more servers with the same number of minimum views?
Mar 17 '07 #2

but what if there are two or more servers with the same number of minimum views?
Thanks for taking the time to reply Kevin, I really appreciate this. I tried running this with more than one server set to the same number of views and it picks the one it comes across first in the list. This is fine as this code will be placed in a pre-existing script that people use to create views. We're just trying to prevent an imbalance of views across the five servers that are available. If there is a tie among the lowest number of views, as long as one of them gets picked during a given round that'll work.

Again, thanks so much.

Joe
Mar 18 '07 #3
@joeke3el

If you want to read more about the backgrounds of Kevin's solution, it's called the "Schwarztian Transform".

Greetz, Doc
Mar 19 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Paul Kirby | last post by:
Hello All I am trying to update me code to use arrays to store a group of information and I have come up with a problem sorting the multiple array :( Array trying to sort: (7 arrays put into...
1
by: David Pratt | last post by:
I have been using the following for sorting a list of dictionaries. This works but only provides sorting on a single key. I am wanting to extend this with a better comparison expression so that it...
2
by: Neil Hindry | last post by:
I wonder if you can help me. I have been using the very basic functions of Access XP for a while now but I have just started delving into forms etc. I have created a form to enter my data and...
19
by: Owen T. Soroke | last post by:
Using VB.NET I have a ListView with several columns. Two columns contain integer values, while the remaining contain string values. I am confused as to how I would provide functionality to...
0
by: Brian Henry | last post by:
Here is another virtual mode example for the .NET 2.0 framework while working with the list view. Since you can not access the items collection of the list view you need to do sorting another...
4
by: FBM | last post by:
Hi, I am working on a program that simulates one of the elements of ATM. The simulation stores events which occurs every some milliseconds for a certain amount of time. Every time that an event...
11
by: dwelden | last post by:
I have successfully used the sort lambda construct described in http://mail.python.org/pipermail/python-list/2006-April/377443.html. However, how do I take it one step further such that some values...
16
by: skip | last post by:
The thread on sorting in Python 3 got me to thinking. How could I sort a list of complex numbers using key? As expected: Traceback (most recent call last): File "<stdin>", line 1, in...
5
by: jrod11 | last post by:
hi, I found a jquery html table sorting code i have implemented. I am trying to figure out how to edit how many colums there are, but every time i remove code that I think controls how many colums...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.