Re: Sorting an array by a substring of its members

2008-12-15 Thread Rob Dixon
Christopher Yee Mon wrote: > I have an array of strings whose members consist of a number followed by > a comma followed by a text string > > e.g. > 1,fresh > 2,testurl > > I want to sort by descending numerical order according to the number > part so I made this sort subroutine > > sub by_cou

Re: Sorting an array by a substring of its members

2008-12-15 Thread Christopher Yee Mon
hmm. i just tried it and it worked. I guess it's one of those situations. thanks Christopher John W. Krahn wrote: > Christopher Yee Mon wrote: >> I have an array of strings whose members consist of a number followed >> by a comma followed by a text string >> >> e.g. >> 1,fresh >> 2,testurl >> >>

Re: Sorting an array by a substring of its members

2008-12-15 Thread Mr. Shawn H. Corey
On Mon, 2008-12-15 at 20:33 -0500, Christopher Yee Mon wrote: > I have an array of strings whose members consist of a number followed by > a comma followed by a text string > > e.g. > 1,fresh > 2,testurl > > I want to sort by descending numerical order according to the number > part so I made t

Re: Sorting an array by a substring of its members

2008-12-15 Thread John W. Krahn
Brian Tillman wrote: I'm probably missing something, but what's wrong with?: sort {$b <=> $a} @array; Nothing, unless you have, as you really should, warnings enabled: $ perl -le' use warnings; my @array = ( "1,fresh", "2,testurl" ); @array = sort { $b <=> $a } @array; print for @array; ' Arg

Re: Sorting an array by a substring of its members

2008-12-15 Thread Christopher Yee Mon
well if the contents of the array are '1,fresh' and '2,testurl' I think that'll try to do a numerical sort on the pair of strings which wouldn't do anything. I have tried { $b <=> $a } and it didn't work. I want the sort to take the two strings and sort the strings but only sort by the numerical p

Re: Sorting an array by a substring of its members

2008-12-15 Thread John W. Krahn
Christopher Yee Mon wrote: I have an array of strings whose members consist of a number followed by a comma followed by a text string e.g. 1,fresh 2,testurl I want to sort by descending numerical order according to the number part so I made this sort subroutine sub by_counter_field { my($a

Re: Sorting an array by a substring of its members

2008-12-15 Thread Brian Tillman
I'm probably missing something, but what's wrong with?: sort {$b <=> $a} @array; On Dec 15, 2008, at 6:33 PM, Christopher Yee Mon > wrote: I have an array of strings whose members consist of a number followed by a comma followed by a text string e.g. 1,fresh 2,testurl I want to sort by

Re: Sorting an Array of Arrays

2007-03-14 Thread Randal L. Schwartz
> ""Mumia" == "Mumia W " writes: "Mumia> On 03/13/2007 07:44 PM, Hardly Armchair wrote: >> Hello List, >> I have a data structure containing a bunch of strings in different groups: >> [...] >> I want these sorted first alphabetically within the group, and then >> according to the number of me

Re: Sorting an Array of Arrays

2007-03-13 Thread Mumia W.
On 03/13/2007 07:44 PM, Hardly Armchair wrote: Hello List, I have a data structure containing a bunch of strings in different groups: [...] I want these sorted first alphabetically within the group, and then according to the number of member in the group. [...] This is slightly more compact

Re: Sorting an Array of Arrays

2007-03-13 Thread John W. Krahn
Hardly Armchair wrote: > Hello List, Hello, > I have a data structure containing a bunch of strings in different groups: > > $groups = [ > [ > 'SSPDQR', > 'SSPSDR', > 'STSSER', > ], > [ > 'CSANLH', >

Re: sorting an array of arrays by arr_el[$idx][2] (or something like that)

2006-04-18 Thread John W. Krahn
Charles K. Clarkson wrote: > Ed wrote: > > : push( @lineArray, @_ ); <---no it's an array of arrays. > > An array of arrays is a short name for an array of array > references. Array elements can only hold scalar values and arrays > are not scalars. References to arrays are scalars.

Re: sorting an array of arrays by arr_el[$idx][2] (or something like that)

2006-04-18 Thread John W. Krahn
Thomas Bätzler wrote: > Ed <[EMAIL PROTECTED]> asked: >> >> push( @lineArray, @_ ); <---no it's an array of arrays. > > This will append all the items in @_ to @lineArray. > > You shoul've said "push( @lineArray, [EMAIL PROTECTED] );" instead. No he shouldn't have. @_ is a global

Re: sorting an array of arrays by arr_el[$idx][2] (or something like that)

2006-04-18 Thread M. Kristall
Ed wrote: I want to sort the lines in the file by the 3rd column (Field, Internal, CM, DocAdmin) Since Perl doesn't really support multidimensional arrays but instead uses references, something like this should work: sort { $$a[2] cmp $$b[2] } @array; This is more or less like the typical sort

RE: sorting an array of arrays by arr_el[$idx][2] (or something like that)

2006-04-17 Thread Charles K. Clarkson
Ed wrote: : my @lineArray; : while() : { : # if the line is a net localgroup line add it to the array : if( $_ =~ $s_criteria ) You probably should be testing against a regular expression. if ( $_ =~ /$s_criteria/ ) Or just: if ( /$s_criteria/ ) :

RE: sorting an array of arrays by arr_el[$idx][2] (or something like that)

2006-04-17 Thread Thomas Bätzler
Ed <[EMAIL PROTECTED]> asked: [...] > I'm reading from a file and constructing an array of arrays. > Here's an example of what's in the file: > net localgroup Field Aidan /ADD [...] > I want to sort the lines in the file by the 3rd column > (Field, Internal, CM, DocAdmin) If you're not particular

RE: Sorting an array of hashes

2004-08-06 Thread Chris Mortimore
-Original Message- From: Chris Mortimore [mailto:[EMAIL PROTECTED] Sent: Thursday, August 05, 2004 5:19 PM To: [EMAIL PROTECTED] Subject: Sorting an array of hashes I want to sort an AoH. Not each hash by its keys, but the array by the value of one of the keys in each hash. I know how t

Re: Sorting an array of hashes

2004-08-05 Thread Gunnar Hjalmarsson
Chris Mortimore wrote: Gunnar Hjalmarsson wrote: Chris Mortimore wrote: I want to sort an AoH. Not each hash by its keys, but the array by the value of one of the keys in each hash. The value of one of the keys? If you don't know *which* key in respective hash, this appears to be pretty tricky...

Re: Sorting an array of hashes

2004-08-05 Thread Randy W. Sims
On 8/5/2004 5:18 PM, Chris Mortimore wrote: I want to sort an AoH. Not each hash by its keys, but the array by the value of one of the keys in each hash. I know how to sort a simple array. I know how to sort a hash by the keys. Could someone kindly point me to the documentation on sorting arrays o

RE: Sorting an array of hashes

2004-08-05 Thread Moon, John
-Original Message- From: Chris Mortimore [mailto:[EMAIL PROTECTED] Sent: Thursday, August 05, 2004 5:19 PM To: [EMAIL PROTECTED] Subject: Sorting an array of hashes I want to sort an AoH. Not each hash by its keys, but the array by the value of one of the keys in each hash. I know how to

RE: Sorting an array of hashes

2004-08-05 Thread Chris Devers
On Thu, 5 Aug 2004, Chris Mortimore wrote: Gunnar Hjalmarsson wrote: > Chris Mortimore wrote: >> I want to sort an AoH. Not each hash by its keys, but the array by >> the value of one of the keys in each hash. > > The value of one of the keys? If you don't know *which* key in > respective hash, th

RE: Sorting an array of hashes

2004-08-05 Thread Chris Mortimore
Chris Mortimore wrote: > I want to sort an AoH. Not each hash by its keys, but the array by > the value of one of the keys in each hash. The value of one of the keys? If you don't know *which* key in respective hash, this appears to be pretty tricky... -- Gunnar Hjalmarsson Email: http://www.g

Re: Sorting an array of hashes

2004-08-05 Thread Gunnar Hjalmarsson
Chris Mortimore wrote: I want to sort an AoH. Not each hash by its keys, but the array by the value of one of the keys in each hash. The value of one of the keys? If you don't know *which* key in respective hash, this appears to be pretty tricky... -- Gunnar Hjalmarsson Email: http://www.gunnar.cc

RE: Sorting an Array with classobjects

2003-02-27 Thread Hanson, Rob
Try this... @sortarr = sort {$a->{Classvalue} <=> $b->{Classvalue}} (@unsortedobjectarray) $a and $b *ARE THE OBJECTS*, not the index. Rob -Original Message- From: Nils-Anders Persson [mailto:[EMAIL PROTECTED] Sent: Thursday, February 27, 2003 9:14 AM To: [EMAIL PROTECTED] Subject: Sor

Re: Sorting an array based on hash values

2002-06-20 Thread Jeff 'japhy' Pinyan
On Jun 20, Kevin Old said: >I have a hash with the key being the field name and the value being the >order in which the field is to be displayed.like below: > >%order = ( > DATE => '1', > CPP => '2', > ESN => '3', > BTS => '4' > ); > >I'm receiving an array t

RE: sorting an array

2002-02-18 Thread Wagner-David
Here is a shot using map. I moved the data around(basically in backwards so would know if sorted). Ran with warnings under as build 623: my %DayOfWeek = ( 'jan', 1, 'feb', 2, 'mar', 3, 'apr', 4, 'may', 5, 'jun', 6, 'jul', 7, 'aug', 8, 'sep', 9, 'oct',10, 'nov',11, 'dec

RE: sorting an array

2002-02-18 Thread Yacketta, Ronald
} } } sort the array foreach $line (sort sortby @cheaters) -Ron > -Original Message- > From: Frank [mailto:[EMAIL PROTECTED]] > Sent: Monday, February 18, 2002 12:43 > To: Yacketta, Ronald > Subject: Re: sorting an array > > > On Mon, Feb

Re: sorting an array

2002-02-18 Thread Frank
On Mon, Feb 18, 2002 at 11:03:33AM -0500, Yacketta, wrote: > Folks, > > I have an array which contains data as such > > psych|Sun Feb 17 2002|0:35:59|1523882|HLHack|UG-CS Central-Hell's Kitchen > uenlon|Sun Feb 17 2002|3:31:17|127244|HLHack|UG-CS Central-Hell's Kitchen > uenlon|Sun Feb 17 200

RE: Sorting an array of hashes

2002-02-06 Thread Tomasi, Chuck
06, 2002 1:28 PM > To: 'Tomasi, Chuck'; '[EMAIL PROTECTED]' > Subject: RE: Sorting an array of hashes > > > @sorted = sort { > $a->{ID} <=> $b->{ID} ## remember that $a and $b > become the element > of the array > ## so if

Re: Sorting an array of hashes

2002-02-06 Thread Brett W. McCoy
On Wed, 6 Feb 2002, Tomasi, Chuck wrote: > Does anyone have any clever ideas for sorting an array of hashes based on > a key such as an ID number? > > Example: > > @AoH = ( > { ID => 10101, UserID => 1041, Status => 2 }, > { ID => 10541, UserID => 1211, Status => 1 }, > { ID

Re: Sorting an array of hashes

2002-02-06 Thread Shawn
- Original Message - From: "Tomasi, Chuck" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Wednesday, February 06, 2002 1:17 PM Subject: Sorting an array of hashes > Does anyone have any clever ideas for sorting an array of hashes based on > a key such as an ID number? > > Example:

Re: Sorting an array of hashes

2002-02-06 Thread Chas Owens
On Wed, 2002-02-06 at 14:17, Tomasi, Chuck wrote: > Does anyone have any clever ideas for sorting an array of hashes based on > a key such as an ID number? > > Example: > > @AoH = ( > { ID => 10101, UserID => 1041, Status => 2 }, > { ID => 10541, UserID => 1211, Status => 1 }, >

RE: Sorting an array of hashes

2002-02-06 Thread Nikola Janceski
@sorted = sort { $a->{ID} <=> $b->{ID} ## remember that $a and $b become the element of the array ## so if it's a reference to a hash use a dereferencer '->' or # $$a{ID} <=> $$b{ID} # will work too! } @AoH; foreach $item (@sorted){ print $item->{

Re: Sorting an array by one of it's fields.

2001-06-18 Thread Tirthankar C.P
Thanks a million to Jos Boumans, and Me (whoever that is). Me, thanks for the explanation, and Jos, for your patient and detailed answer. -tir On Sat, 16 Jun 2001, Me wrote: > > This should've worked. But why do I get a warning: > > > > Use of uninitialized value at ./mk2_ratingchangedb.p

Re: Sorting an array by one of it's fields.

2001-06-16 Thread Me
> This should've worked. But why do I get a warning: > > Use of uninitialized value at ./mk2_ratingchangedb.pl line 39, chunk 8. Whenever you're dealing with baffling array errors like this, always think of off-by-one. In this case: > 30 for ($i=1; ...) { > 31 $dummy[$i][

Re: Sorting an array by one of it's fields.

2001-06-16 Thread Jos I. Boumans
same applies here again. this is the trick used: we dig out that value we want to sort on, make that the key of our hash and go from there let me adres the @arr you presented. ### EXAMPLE 1 ### ### this will NOT eliminate the value we're sorting on from the list ### while ( my @s = splice(@a

Re: Sorting an array by one of it's fields.

2001-06-16 Thread Tirthankar C.P
Thnaks a lot Jos. The idea of reading the array into a hash is quite appealing, and simple too. But I have a small problem with this: What if I want to sort on the second column of the array? Or if there are more than two columns? Say we have: my @arr = qw( 1 2 3 4 4 5 6 7 5 6 7 8 1 2 3 4 3

Re: Sorting an array by one of it's fields.

2001-06-16 Thread Jos I. Boumans
ok, so if i get this right, @dummy has the following format: my @dummy = qw( 1996013100:00:00MAAA 281100:00:00MA- 1997063000:00:00MAAA 1998122200:00:00MAA 2000112400:00:00MD ); now we have that established, let'