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
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
>>
>>
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
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
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
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
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
> ""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
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
Hardly Armchair wrote:
> Hello List,
Hello,
> I have a data structure containing a bunch of strings in different groups:
>
> $groups = [
> [
> 'SSPDQR',
> 'SSPSDR',
> 'STSSER',
> ],
> [
> 'CSANLH',
>
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.
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
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
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/ )
:
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
-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
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...
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
-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
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
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
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
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
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
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
}
}
}
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
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
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
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
- 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:
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 },
>
@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->{
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
> 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][
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
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
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'
37 matches
Mail list logo