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

Sorting an array by a substring of its members

2008-12-15 Thread Christopher Yee Mon
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, $b) = @_; $a =~ s/^(.*?),

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', >

Sorting an Array of Arrays

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

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

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

2006-04-17 Thread Ed
I'm still hobbled by my thinking in C problem so I'm looking for a way to do this. 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 net localgroup Internal Aidan /ADD net localgroup CM Aidan /ADD net localgroup Do

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

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

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

Sorting an array of hashes

2004-08-05 Thread Chris Mortimore
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 of hashes? Thank you! Chris. >>>-> <-

RE: Sorting an Array with classobjects

2003-02-27 Thread Hanson, Rob
TED] Subject: Sorting an Array with classobjects Hello Perlgurus! I have made a small program that creates some instances of a classobject and puts them into an array. I want to sort this array in order of a specific value in the class. I was thinking of something like this but it doesn't work

Sorting an Array with classobjects

2003-02-27 Thread Nils-Anders Persson
Hello Perlgurus! I have made a small program that creates some instances of a classobject and puts them into an array. I want to sort this array in order of a specific value in the class. I was thinking of something like this but it doesn't work @sortarr = sort byvalue (@unsortedobjectarray) sub

Sorting an array based on the values in a hash

2002-06-20 Thread Kevin Old
Hello all, 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 that would look somethi

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

Sorting an array based on hash values

2002-06-20 Thread Kevin Old
Hello all, 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 that would look somethi

RE: sorting an array

2002-02-18 Thread Wagner-David
l's Kitchen juihung|Sun Feb 17 2002|7:4:56|1149357|HLHack|UG-CS Central-Hell's Kitchen juihung|Sun Feb 17 2002|7:4:57|1149357|HLHack|UG-CS Central-Hell's Kitchen S02|Sun Feb 17 2002|7:13:18|831398|HLHack|UG-CS Central-Hell's Kitchen S02|Sun Feb 17 2002|7:13:20|831398|HLHack|U

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

sorting an array

2002-02-18 Thread Yacketta, Ronald
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 2002|3:31:19|127244|HLHack|UG-CS Central-Hell's Kitchen juihung|Sun Feb 17

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 =>

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 a

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 =>

RE: Sorting an array of hashes

2002-02-06 Thread Nikola Janceski
$item (@sorted){ print $item->{ID}, "\n"; } -Original Message- From: Tomasi, Chuck [mailto:[EMAIL PROTECTED]] Sent: Wednesday, February 06, 2002 2:18 PM To: '[EMAIL PROTECTED]' Subject: Sorting an array of hashes Does anyone have any clever ideas

Sorting an array of hashes

2002-02-06 Thread Tomasi, Chuck
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 => 10111, UserID => 1211, Sta

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'

Sorting an array by one of it's fields.

2001-06-16 Thread Tirthankar C.P
Folks, # How do I sort an array by one of it's fields? I have a this code: for ($i=1; $i<=$N; $i++) { } $dummy[$i][0] = &ParseDate($data{$key}[$i][0]); if (! $dummy[$i][0]) { } warn "Could not parse $data{$key}[$i][0]\n"; } $dummy[$i][1] = $da

Re: Counting and sorting an array

2001-05-18 Thread Timothy Kimball
Slight correction: : pushd @petcounts, sprintf "<%d> %s%s", should be push @petcounts, sprintf "<%d> %s%s", -- tdk

Re: Counting and sorting an array

2001-05-18 Thread Timothy Kimball
: I would like to sort an array like this : my @pets = {$cat, $dog,$camel,$camel,$camel,$dog} : and then to have it printed out in the order of occurrences : print "I will give you <3> camels, <2> dogs, <1> cat " for the blond one Well, first of all, what you have there isn't really an array.

Counting and sorting an array

2001-05-17 Thread Kenan
Hi , I would like to sort an array like this my @pets = {$cat, $dog,$camel,$camel,$camel,$dog} and then to have it printed out in the order of occurrences print "I will give you <3> camels, <2> dogs, <1> cat " for the blond one Tnx Kenan