Re: Sorting from subroutine call

2006-12-02 Thread Rob Dixon
Sergio Escalada wrote: Hi all! I would like to know if it's possible to make an array sorting with a subroutine call. Usually, a sort is made as, for example: sort {$a = $b} @array; But my intention is something like: sort subroutine_call @array; sub subroutine { $a = $b; } How could

Re: Sorting from subroutine call

2006-12-02 Thread Sergio Escalada
Thanks for replies. The purpouse of this mini-script is to list the rows from a database loaded in memory ($ref_db is the reference to hashtable that cotains the DB). So I want to order the fields by different sort rules, and make the proccess as abstract as it's possible with a subrutine (sub

Re: Sorting from subroutine call

2006-12-02 Thread Bill Jones
On 12/2/06, Sergio Escalada [EMAIL PROTECTED] wrote: The purpouse of this mini-script is to list the rows from a database loaded in memory ($ref_db is the reference to hashtable Another idea - sub sortrows { my $sorted = @_; $sorted = -(($a-{ahash} eq 'x') = ($b-{ahash} eq 'x')) if

Re: Sorting from subroutine call

2006-12-02 Thread Lawrence Statton XE2/N1GAK
The purpouse of this mini-script is to list the rows from a database loaded in memory ($ref_db is the reference to hashtable that cotains the DB). So I want to order the fields by different sort rules, and make the proccess as abstract as it's possible with a subrutine (sub cmpRule). This sub

Re: Sorting from subroutine call

2006-12-02 Thread Mumia W.
On 12/02/2006 06:22 AM, Sergio Escalada wrote: Hi all! I would like to know if it's possible to make an array sorting with a subroutine call. Usually, a sort is made as, for example: sort {$a = $b} @array; But my intention is something like: sort subroutine_call @array; sub subroutine

Re: Sorting from subroutine call

2006-12-02 Thread Sergio Escalada
# # hashref? Why in the WORLD is the database being kept in a hashref? # Oh, it's an exercise for class, and I must keep data in a hashtable, it's not my fault ^_^ Thanks for your code :) # # if you have a small number of columns you want to sort by, build a # simple subroutine to sort by

Re: Sorting from subroutine call

2006-12-02 Thread D. Bolliger
sorting subroutines explicitly, since their number may be high (sort by one ore more fields, in different order, ascending/descending, numeric/string sort - in different combinations. Instead, we code an abstract subroutine (sort_sub_factory) that returns sorting subroutines created

Re: Sorting from subroutine call

2006-12-02 Thread Sergio Escalada
possible to give a code block (delivering a subroutine reference) as argument to sort that does the actual sort. 2. We don't code these different possible sorting subroutines explicitly, since their number may be high (sort by one ore more fields, in different order, ascending/descending

Looking for a Perl module for proper IP sorting

2006-11-13 Thread Roman Daszczyszak
sorting? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response

Re: Looking for a Perl module for proper IP sorting

2006-11-13 Thread Bjørge Solli
instead of the via the 4th octet. Is there a Perl module that does proper IP sorting? http://search.cpan.org/~sarenner/Net-IPAddress-1.10/IPAddress.pm You can use the ip2num, sort and then num2ip. OR: You can represent them with IP-objects: http://search.cpan.org/~luismunoz/NetAddr-IP-4.004

Re: Looking for a Perl module for proper IP sorting

2006-11-13 Thread Sebastian Stumpf
On Mon, 13 Nov 2006 14:38:25 +0100 Roman Daszczyszak [EMAIL PROTECTED] wrote: Is there a Perl module that does proper IP sorting? I think you could use NetAddr::IP for that job. Or something simpler like that: use Socket; @sorted = map { inet_ntoa($_) } sort map { inet_aton($_) } @unsorted

Re: Looking for a Perl module for proper IP sorting

2006-11-13 Thread kilaru rajeev
Hi Roman, Please sort the IP addresses with this way could help you, @list = sort { $b = $a } @ip_addresses; rgds, Rajeev -- Forwarded message -- From: Roman Daszczyszak [EMAIL PROTECTED] Date: Nov 13, 2006 7:08 PM Subject: Looking for a Perl module for proper IP sorting

Re: Looking for a Perl module for proper IP sorting

2006-11-13 Thread Rob Dixon
module that does proper IP sorting? my @sorted = sort { my @a = $a =~ /(\d+)/g; my @b = $b =~ /(\d+)/g; shift @a = shift @b or shift @a = shift @b or shift @a = shift @b or shift @a = shift @b } @ips; Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail

Re: Looking for a Perl module for proper IP sorting

2006-11-13 Thread John W. Krahn
octet. Is there a Perl module that does proper IP sorting? No need for a module: $ perl -le' print for map unpack( q[x4 A*], $_ ), sort map pack( q[C4 A*], /\d+/g, $_ ), qw[ 192.168.0.1 192.168.0.100 192.168.0.101 192.168.0.114 192.168.0.115 192.168.0.116 192.168.0.117

Re: Looking for a Perl module for proper IP sorting

2006-11-13 Thread Roman Daszczyszak
my @sorted = sort { my @a = $a =~ /(\d+)/g; my @b = $b =~ /(\d+)/g; shift @a = shift @b or shift @a = shift @b or shift @a = shift @b or shift @a = shift @b } @ips; Rob Thanks, that did it! Now I have to figure out why that works... hmm.. Roman -- To unsubscribe, e-mail:

Re: Looking for a Perl module for proper IP sorting

2006-11-13 Thread Roman Daszczyszak
Please sort the IP addresses with this way could help you, @list = sort { $b = $a } @ip_addresses; Wouldn't this do the same kind of sort I've been doing (aka a textual one)? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/

Re: Looking for a Perl module for proper IP sorting

2006-11-13 Thread Sebastian Stumpf
Please sort the IP addresses with this way could help you, @list = sort { $b = $a } @ip_addresses; Wouldn't this do the same kind of sort I've been doing (aka a textual one)? No, I don't think so. perl -MSocket -wle 'print for map { inet_ntoa($_) } sort map { inet_aton($_) } '

Re: sorting DBM hash

2006-09-29 Thread D. Bolliger
John W. Burns am Donnerstag, 28. September 2006 17:11: Sorting DBM Hash Greetings: Hello John W. I've run into what appears to be a conflict in sorting a DBM Hash. The DBM is opened and closed through tie and untie to store selections from Perl Tk medical questionnaire which uses

sorting DBM hash

2006-09-28 Thread John W. Burns
Sorting DBM Hash Greetings: I've run into what appears to be a conflict in sorting a DBM Hash. The DBM is opened and closed through tie and untie to store selections from Perl Tk medical questionnaire which uses checkboxes, radio buttons and lists, and contains over 200 items. I'm attempting

sorting DBM hash

2006-09-28 Thread John W. Burns
Sorting DBM Hash Greetings: I've run into what appears to be a conflict in sorting a DBM Hash. The DBM is opened and closed through tie and untie to store selections from Perl Tk medical questionnaire which uses checkboxes, radio buttons and lists, and contains over 200 items. I'm

Re: Sorting on HoHoH

2006-09-08 Thread Hardly Armchair
John W. Krahn wrote: Hardly Armchair wrote: Hello List, Hello, I have a data structure like so: %p_mod = { ^ You are using the wrong punctuation. That would produce a warning if you had warnings enabled. Sorry. I'm actually generating this data structure dynamically and

Re: Sorting on HoHoH

2006-09-08 Thread Rob Dixon
be greater than 5 (due to the nature of the data), so a default sort will do the same thing as a numeric sort. This is good because it is easy and, I've heard, using default sort is faster than any other way of sorting in Perl. However, I am curious as to how this would be accomplished

Sorting on HoHoH

2006-09-07 Thread Hardly Armchair
a default sort will do the same thing as a numeric sort. This is good because it is easy and, I've heard, using default sort is faster than any other way of sorting in Perl. However, I am curious as to how this would be accomplished the proper way; that is, by numerically sorting the keys

Re: Sorting on HoHoH

2006-09-07 Thread John W. Krahn
that the numbers will never be greater than 5 (due to the nature of the data), so a default sort will do the same thing as a numeric sort. This is good because it is easy and, I've heard, using default sort is faster than any other way of sorting in Perl. However, I am curious as to how

Re: reading input file, sorting then writing output file

2006-07-26 Thread John W. Krahn
macromedia wrote: Hi, Hello, I can't seem to get my script to sort properly. Yes, it is a bit tricky to get right. Below is my code along with a sample input.txt file. I also have what the output.txt file should look like. Also note any duplicate should be striped out which seems to

Re: reading input file, sorting then writing output file

2006-07-26 Thread Mumia W.
perldoc perlop. No, this doesn't quite do it. I see your data is a little more complicated than what I thought before. When you have unusual sorting requirements, you need unusual sorting keys. I decided to use sprintf() to give me keys that are formatted perfectly for sorting: require

Re: reading input file, sorting then writing output file

2006-07-26 Thread Mumia W.
On 07/25/2006 08:32 PM, macromedia wrote: Hi, I can't seem to get my script to sort properly. [...] Here is a shortened version of your program: use strict; use warnings; use File::Slurp; my %tags; foreach my $line (read_file 'sort_tags.dat') { if ($line =~ m/id=(\d*)([[:alpha:]]*)/) {

RE: reading input file, sorting then writing output file

2006-07-25 Thread macromedia
Hi, I can't seem to get my script to sort properly. Below is my code along with a sample input.txt file. I also have what the output.txt file should look like. Also note any duplicate should be striped out which seems to work ok. Something is getting messed up when I have the numerials along

RE: reading input file, sorting then writing output file

2006-07-25 Thread macromedia
Opps. Once you save my code to a file the syntax woiuld be: perl mycode.pl input.txt output.txt Below is what I get now when I run my code on the input.txt file. As you can see its not sorting the way I like. It should sort like the OUTPUT.TXT file inmy previsou email. tag id=1Test./tag

Re: reading input file, sorting then writing output file

2006-07-25 Thread Mumia W.
On 07/25/2006 08:32 PM, macromedia wrote: Hi, I can't seem to get my script to sort properly. Below is my code [...] sort { $a-[0] cmp $b-[0] || $a-[7] = $b-[7] } [...] Cmp does string comparisons. Use = for numeric comparisons. Read perldoc perlop. -- To

Re: sorting a nested array?

2006-07-21 Thread Mumia W.
at this level to key/sort on [0] - this level contains the 'meat' ...data... {typedefName} = xyz; - would like to sort on this but its nested [1] [1] Normally for sorting on an array we can do my @funcs

sorting a nested array?

2006-07-20 Thread Alan Campbell
] - this level contains the 'meat' ...data... {typedefName} = xyz; - would like to sort on this but its nested [1] [1] Normally for sorting on an array we can do my @funcs = sort {$a-{typedefName} cmp $b-{typedefName

Re: sorting?

2006-05-30 Thread Sumo Wrestler (or just ate too much)
Beast wrote: Hi, I have some rather big chunk of data, returned from ldap server. The format is simple: Displa name [EMAIL PROTECTED] Simply displying data as is is simple, but how do I sorted by display name? pls note that display name contains space and might not unique so I can't put

Re: sorting?

2006-05-30 Thread D. Bolliger
Beast am Mittwoch, 31. Mai 2006 07.59: Hi, Hi I have some rather big chunk of data, returned How 'returned'? from ldap server. The format is simple: Displa name [EMAIL PROTECTED] Simply displying in the sense of printing to STDOUT? data as is is simple, but how do I sorted by

Re: sorting?

2006-05-30 Thread Chandru
Hi $ cat data chandru k [EMAIL PROTECTED] prg [EMAIL PROTECTED] chandru k [EMAIL PROTECTED] $ cat script.pl #!/usr/bin/perl while() { chomp; ($mail,$name)=split(/\t/,reverse($_),2); $ha{reverse($mail)}=reverse($name); } foreach $k(sort values(%ha)) { print $k\n;

Re: sorting?

2006-05-30 Thread Beast
Beast wrote: Hi, I have some rather big chunk of data, returned from ldap server. The format is simple: Displa name [EMAIL PROTECTED] Simply displying data as is is simple, but how do I sorted by display name? pls note that display name contains space and might not unique so I can't put

Re: sorting?

2006-05-30 Thread D. Bolliger
Beast am Mittwoch, 31. Mai 2006 12.06: Beast wrote: Hi, I have some rather big chunk of data, returned from ldap server. The format is simple: Displa name [EMAIL PROTECTED] Simply displying data as is is simple, but how do I sorted by display name? pls note that display name

sorting?

2006-05-29 Thread Beast
Hi, I have some rather big chunk of data, returned from ldap server. The format is simple: Displa name [EMAIL PROTECTED] Simply displying data as is is simple, but how do I sorted by display name? pls note that display name contains space and might not unique so I can't put it on %hash.

Re: sorting?

2006-05-29 Thread Wijaya Edward
- Original Message - From: Beast [EMAIL PROTECTED] Date: Wednesday, May 31, 2006 1:59 pm Subject: sorting? Hi, I have some rather big chunk of data, returned from ldap server. The format is simple: Displa name [EMAIL PROTECTED] Simply displying data as is is simple, but how

Sorting files by date

2006-05-24 Thread cajun
I have a rather large group of files (~5000) that I would like to sort into directories by date. Initially by year, then perhaps later by year/month. I'm looking at the -M operator, but it seems like that would require you find the number of days of the year, today is, then do the math.

Re: Sorting files by date

2006-05-24 Thread John W. Krahn
[EMAIL PROTECTED] wrote: I have a rather large group of files (~5000) that I would like to sort into directories by date. Initially by year, then perhaps later by year/month. I'm looking at the -M operator, but it seems like that would require you find the number of days of the year, today

Re: Re: Sorting files by date

2006-05-24 Thread cajun
[EMAIL PROTECTED] wrote: [EMAIL PROTECTED] wrote: I have a rather large group of files (~5000) that I would like to sort into directories by date. Initially by year, then perhaps later by year/month. I'm looking at the -M operator, but it seems like that would require you

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

2006-04-18 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 particularly

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

2006-04-18 Thread Charles K. Clarkson
Ed wrote: : my @lineArray; : while(F) : { : # 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-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

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 variable so

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.

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

Sorting hash values

2006-04-05 Thread Baskaran Sankaran
Hi group, I am trying to process a hash (words as keys and frequency counts in an array as values). Instead of just sorting it by values, I want to sort it by the probabilities and I tried this... foreach $rule (sort {\compute_probability($b) = \compute_probability($a)} keys %rules_new

Re: Sorting hash values

2006-04-05 Thread Jeff Pang
And it doesn't work. Any help is appreciated. Hello,I'd modify your script as follow,and it could work for me. use strict; use warnings; my %rules_new = (aaa = [11,22,33,44], bbb = [55,66,77,88], ); for my $rule (sort {compute_probability($b) =

sorting

2006-03-19 Thread Ash Varma
Hi.. I have: $code[0][0] = AAA $code[0][1] = 19.5 $code[1][0] = AAD $code[1][1] = 20.0 $code[2][0] = ZZZ $code[2][1] = 10.7 $code[3][0] = XXA $code[3][1] = 5.9 $code[4][0] = YXA $code[4][1] = 27.1 $code[5][0] = AZX $code[5][1] = 1.9 What would be the best way to sort this? -- Ash Varma

Re: sorting

2006-03-19 Thread Randal L. Schwartz
Ash == Ash Varma [EMAIL PROTECTED] writes: Ash Hi.. Ash I have: Ash $code[0][0] = AAA Ash $code[0][1] = 19.5 Ash $code[1][0] = AAD Ash $code[1][1] = 20.0 Ash $code[2][0] = ZZZ Ash $code[2][1] = 10.7 Ash $code[3][0] = XXA Ash $code[3][1] = 5.9 Ash $code[4][0] = YXA Ash $code[4][1] = 27.1 Ash

Re: sorting

2006-03-19 Thread Christer Ekholm
Ash Varma [EMAIL PROTECTED] writes: Hi.. I have: $code[0][0] = AAA $code[0][1] = 19.5 $code[1][0] = AAD $code[1][1] = 20.0 $code[2][0] = ZZZ $code[2][1] = 10.7 $code[3][0] = XXA $code[3][1] = 5.9 $code[4][0] = YXA $code[4][1] = 27.1 $code[5][0] = AZX $code[5][1] = 1.9 What would

Re: sorting

2006-03-19 Thread Ash Varma
sorry for an incomplete question, but this is exactly what I was after.. :) Thanks On 3/20/06, Christer Ekholm [EMAIL PROTECTED] wrote: Ash Varma [EMAIL PROTECTED] writes: Hi.. I have: $code[0][0] = AAA $code[0][1] = 19.5 $code[1][0] = AAD $code[1][1] = 20.0 $code[2][0] =

Re: Sorting a hash of hashes

2006-02-03 Thread John W. Krahn
Scott Palmer wrote: I am attempting to sort by a field in a hash within a hash and I am having a hard time finding the right direction. I want the print out to sort from smallest to largest in size. Any help would be greatly appreciated. --

Sorting a hash of hashes

2006-02-02 Thread Scott Palmer
I am attempting to sort by a field in a hash within a hash and I am having a hard time finding the right direction. I want the print out to sort from smallest to largest in size. Any help would be greatly appreciated. Scott -- #!/usr/bin/perl # Set your

RE: Sorting a hash of hashes

2006-02-02 Thread Wagner, David --- Senior Programmer Analyst --- WGO
Scott Palmer wrote: I am attempting to sort by a field in a hash within a hash and I am having a hard time finding the right direction. I want the print out to sort from smallest to largest in size. Any help would be greatly appreciated. Scott --

RE: sorting hash

2005-12-27 Thread Timothy Johnson
A variation on the same theme, for sorting by value instead of key: use strict; use warnings; my %hash = qw(1 A 2 B 3 C); foreach my $key ( sort {$hash{$a} = $hash{$b} } keys %hash ) { print $key = $hash{$key}\n; } -Original Message- From: Charles K. Clarkson

sorting hash

2005-12-26 Thread Anders Stegmann
Hi! I have a script like: %hash = qw(1 A 2 B 3 C); while (($key, $value) = each %hash) { print $key = $value\n; } it prints out: 1 = A 3 = C 2 = B I want it to print out a sorted hash like: 1 = A 2 = B 3 = C How do I do that? Regards Anders. Anders Stegmann Ph.d. student

Re: sorting hash

2005-12-26 Thread John Doe
Anders Stegmann am Montag, 26. Dezember 2005 15.22: Hi! Hello I have a script like: %hash = qw(1 A 2 B 3 C); while (($key, $value) = each %hash) { print $key = $value\n; } it prints out: 1 = A 3 = C 2 = B I want it to print out a sorted hash like: 1 = A 2 = B 3 = C How

RE: sorting hash

2005-12-26 Thread Charles K. Clarkson
structure for your solution? If you are sorting a hash more than once, you may want to use a sorted hash module or you may want to use a different data structure. HTH, Charles K. Clarkson -- Mobile Homes Specialist 254 968-8328 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands

Svar: RE: sorting hash

2005-12-26 Thread Anders Stegmann
question is: Are you using the right data structure for your solution? If you are sorting a hash more than once, you may want to use a sorted hash module or you may want to use a different data structure. HTH, Charles K. Clarkson -- Mobile Homes Specialist 254 968-8328 -- To unsubscribe, e-mail

Sorting hash of hashes

2005-10-06 Thread Rose, Jeff
I have been trying to sort a hash but I cannot figure it out for the life of me The hash is in the form: my %message { messageid { From= To=

Re: Sorting hash of hashes

2005-10-06 Thread Jeff 'japhy' Pinyan
all the way at the end of the things you're sorting. I don't think you actually know what $a and $b are. $a and $b represent two elements of the list you're sorting -- this means they're two keys from %message. This means the ONLY place it makes sense for them to be is $message

Re: Need help with sorting on perl template toolkit

2005-09-12 Thread Anish Kumar K
Hi Sorry for the trouble...I got it we can use reverse function... Once again Sorry Anish - Original Message - From: Anish Kumar K To: beginners@perl.org Sent: Monday, September 12, 2005 11:20 AM Subject: Need help with sorting on perl template toolkit Hi I

Need help with sorting on perl template toolkit

2005-09-11 Thread Anish Kumar K
Hi I needed the help as how to sort descending in a hash [%FOREACH keyValue = wordCount.nsort(wordCount.$keyValue)%] tr bgcolor=[%BGCOLOR%] td[% keyValue %]/td td[% wordCount.$keyValue %]/td /tr [%END%] This is sorting in ASCENFDING order. I tried out giving - , NOT ASC

more hashref within array sorting

2005-08-09 Thread Jeremy Kister
I've got an array full of hashrefs: my @a = ( {N = '10.1.2.1'}, {N = '10.1.9.1'}, {N = '10.3.5.1'}, {N = '10.1.1.3'}, ); I want to sort this array, and print. I expect the output resemble: 10.1.1.3 10.1.2.1 10.1.9.1 10.3.5.1 I've fumbled with this for a

Re: more hashref within array sorting

2005-08-09 Thread Paul Johnson
On Tue, Aug 09, 2005 at 06:03:18AM -0400, Jeremy Kister wrote: I've got an array full of hashrefs: my @a = ( {N = '10.1.2.1'}, {N = '10.1.9.1'}, {N = '10.3.5.1'}, {N = '10.1.1.3'}, ); I want to sort this array, and print. I expect the output

Re: more hashref within array sorting

2005-08-09 Thread Jeremy Kister
On 8/9/2005 6:26 AM, Paul Johnson wrote: my @s = map { $_ - [0] } sort { $a-[0] = $b-[0] || $a-[1] = $b-[1] || $a-[2] = $b-[2] || $a-[3] = $b-[3] } map { [ $_, split /\./ ] } map { $_-{N} } @a; You clearly solved the

Re: more hashref within array sorting

2005-08-09 Thread Paul Johnson
On Tue, Aug 09, 2005 at 06:53:33AM -0400, Jeremy Kister wrote: On 8/9/2005 6:26 AM, Paul Johnson wrote: my @s = map { $_ - [0] } sort { $a-[0] = $b-[0] || $a-[1] = $b-[1] || $a-[2] = $b-[2] || $a-[3] = $b-[3] } map { [

Re: more hashref within array sorting

2005-08-09 Thread John W. Krahn
Jeremy Kister wrote: On 8/9/2005 6:26 AM, Paul Johnson wrote: my @s = map { $_ - [0] } sort { $a-[0] = $b-[0] || $a-[1] = $b-[1] || $a-[2] = $b-[2] || $a-[3] = $b-[3] } map { [ $_, split /\./ ] } map { $_-{N} } @a; You

Re: more hashref within array sorting

2005-08-09 Thread Jeremy Kister
On 8/9/2005 8:43 AM, John W. Krahn wrote: Jeremy Kister wrote: I've apparently dumbed down my code and question a bit too much: I have multiple hashrefs in each element of the array, and I need the resulting sorted array to contain all the data in the original array, simply sorted by the value

Re: more hashref within array sorting

2005-08-09 Thread Jeff 'japhy' Pinyan
On Aug 9, Jeremy Kister said: my @s = map $_-[ 1 ], sort { $a-[ 0 ] cmp $b-[ 0 ] } map [ inet_aton( $_-{ N } ), $_ ], @a; Now to analyze WTF we're doing here :) Paul's answer had a slight typo in it -- he was comparing $a-[0], $a-[1], $a-[2], and $a-[3], when he

Re: more hashref within array sorting

2005-08-09 Thread Paul Johnson
On Tue, Aug 09, 2005 at 05:00:44PM -0400, Jeff 'japhy' Pinyan wrote: On Aug 9, Jeremy Kister said: my @s = map $_-[ 1 ], sort { $a-[ 0 ] cmp $b-[ 0 ] } map [ inet_aton( $_-{ N } ), $_ ], @a; Now to analyze WTF we're doing here :) Paul's answer had a slight

Re: sorting list of array

2005-07-15 Thread MNibble
Beast wrote: Jeff 'japhy' Pinyan wrote: Is there any builtin function in perl to sort the above array based on uid, username or fulname? There is a built-in function to sort a list, yes. But the mechanism by which to sort the list is, in this case, up to you to provide. This works:

Re: sorting list of array

2005-07-15 Thread Wiggins d'Anconia
MNibble wrote: Beast wrote: Jeff 'japhy' Pinyan wrote: Is there any builtin function in perl to sort the above array based on uid, username or fulname? There is a built-in function to sort a list, yes. But the mechanism by which to sort the list is, in this case, up to you to

sorting list of array

2005-07-13 Thread Beast
I have an array: my @employee = ( [29243, 'john', 'John doe'], [24322, 'jane', 'Jane doe'], [27282, 'james', 'James doe'] ); Is there any builtin function in perl to sort the above array based on uid, username or fulname? -- --beast --

Re: sorting list of array

2005-07-13 Thread Jeff 'japhy' Pinyan
On Jul 13, Beast said: my @employee = ( [29243, 'john', 'John doe'], [24322, 'jane', 'Jane doe'], [27282, 'james', 'James doe'] ); Is there any builtin function in perl to sort the above array based on uid, username or fulname? There is a

Re: sorting list of array

2005-07-13 Thread Beast
Jeff 'japhy' Pinyan wrote: Is there any builtin function in perl to sort the above array based on uid, username or fulname? There is a built-in function to sort a list, yes. But the mechanism by which to sort the list is, in this case, up to you to provide. This works: my @sorted =

Re: sorting list of array

2005-07-13 Thread Jeff 'japhy' Pinyan
On Jul 13, Beast said: Jeff 'japhy' Pinyan wrote: Is there any builtin function in perl to sort the above array based on uid, username or fulname? There is a built-in function to sort a list, yes. But the mechanism by which to sort the list is, in this case, up to you to provide. This

RE: sorting list of array

2005-07-13 Thread Ankur Gupta
the column on what you want to search as a argument.. my $i = $ARGV[0] || 0; # sort subroutine.. my $subsort = sub { #no warnings; $a-[$i] = $b-[$i] || $a-[$i] cmp $b-[$i] }; print Sorting by column $i\n; foreach my $j ( sort $subsort @employee ){ print @$j\n; } __END__

RE: sorting list of array

2005-07-13 Thread Ankur Gupta
Jeff 'japhy' Pinyan mailto:[EMAIL PROTECTED] wrote: On Jul 13, Beast said: Jeff 'japhy' Pinyan wrote: Is there any builtin function in perl to sort the above array based on uid, username or fulname? There is a built-in function to sort a list, yes. But the mechanism by which to sort

RE: sorting list of array

2005-07-13 Thread Jeff 'japhy' Pinyan
On Jul 13, Ankur Gupta said: Jeff 'japhy' Pinyan wrote: Is there any builtin function in perl to sort the above array based on uid, username or fulname? my @sorted = sort { $a-[0] = $b-[0] } @employees; Hey, This will sort only numbers. Will have no effect if the values have

RE: Intelligent Sorting

2005-07-07 Thread Ryan Frantz
Here is one way to approach: !perl use strict; use warnings; my %AlphaToNbr = qw(jan 1 feb 2 mar 3 apr 4 may 5 jun 6 jul 7 aug 8 sep 9 oct 10 nov 11 dec 12); foreach my $MySortedFile (sort { $a-[1] = $b-[1] or $AlphaToNbr{lc($a-[2])} = $AlphaToNbr{lc($b-

RE: Intelligent Sorting

2005-07-07 Thread Jeff 'japhy' Pinyan
On Jul 7, Ryan Frantz said: foreach my $MySortedFile (sort { $a-[1] = $b-[1] or $AlphaToNbr{lc($a-[2])} = $AlphaToNbr{lc($b- [2])} or $a-[3] = $b-[3] } map {[$_, /^.(\d{4})(\w{3})(\d{2})/]}

RE: Intelligent Sorting

2005-07-07 Thread Wagner, David --- Senior Programmer Analyst --- WGO
Ryan Frantz wrote: Here is one way to approach: !perl use strict; use warnings; my %AlphaToNbr = qw(jan 1 feb 2 mar 3 apr 4 may 5 jun 6 jul 7 aug 8 sep 9 oct 10 nov 11 dec 12); foreach my $MySortedFile (sort { $a-[1] = $b-[1] or $AlphaToNbr{lc($a-[2])} =

RE: Intelligent Sorting

2005-07-07 Thread Ryan Frantz
Just take DATA and replace that with @user_links. The code should look like: @user_links = ( sort { $a-[1] = $b-[1] or $AlphaToNumber{lc($a-[2])} = $AlphaToNumber{lc($b-[2])} or $a-[3] = $b-[3] } map {[$_, /^.(\d{4})(\w{3})(\d{2})/]}

Re: Intelligent Sorting

2005-07-07 Thread Wiggins d'Anconia
Ryan Frantz wrote: [snip] Many thanks to Wags and japhy; I've really learned a lot from the both of you. I'm off the pick up 'Programming Perl' after I finish 'Learning Perl'... ry Pick up the Learning Perl Object, References, and Modules book before picking up Programming Perl, it

Re: Intelligent Sorting

2005-07-07 Thread Scott R. Godin
this better? I thought about grabbing the ctime of each file and sorting on that but I'm not sure if that would add unnecessary complexity to the script. The primary problem is that the dates in the filenames are formatted as mmmDD rather than MMDD. Before sorting the filenames, you

Intelligent Sorting

2005-07-06 Thread Ryan Frantz
of each file and sorting on that but I'm not sure if that would add unnecessary complexity to the script. Incidentally, these files are created by SARG (Squid log analyzer) and I've found nothing in the config that lets me customize the naming convention for the directories. ry -- To unsubscribe, e

RE: Intelligent Sorting

2005-07-06 Thread Wagner, David --- Senior Programmer Analyst --- WGO
? I thought about grabbing the ctime of each file and sorting on that but I'm not sure if that would add unnecessary complexity to the script. Incidentally, these files are created by SARG (Squid log analyzer) and I've found nothing in the config that lets me customize the naming convention

RE: Intelligent Sorting

2005-07-06 Thread Ryan Frantz
on. I thought about grabbing the ctime of each file and sorting on that but I'm not sure if that would add unnecessary complexity to the script. Incidentally, these files are created by SARG (Squid log analyzer) and I've found nothing in the config that lets me customize the naming

Re: Intelligent Sorting

2005-07-06 Thread Jeff 'japhy' Pinyan
grabbing the ctime of each file and sorting on that but I'm not sure if that would add unnecessary complexity to the script. The primary problem is that the dates in the filenames are formatted as mmmDD rather than MMDD. Before sorting the filenames, you could convert the month NAMES

sorting array full of hash references

2005-06-07 Thread Jeremy Kister
I'm stumped on how to sort an array based on a hash refrences's key in each element of my array. this is dumbed down code of what I have: my @array; while(my $row = $sth-fetchrow_arrayref){ my %hash = (id = $row-[0], name = $row-[1]); push(@array, \%hash); } after the while loop, I'm trying to

Re: sorting array full of hash references

2005-06-07 Thread John W. Krahn
Jeremy Kister wrote: I'm stumped on how to sort an array based on a hash refrences's key in each element of my array. this is dumbed down code of what I have: my @array; while(my $row = $sth-fetchrow_arrayref){ my %hash = (id = $row-[0], name = $row-[1]); push(@array, \%hash); } after the

Re: sorting array full of hash references

2005-06-07 Thread Peter Rabbitson
On Tue, Jun 07, 2005 at 10:40:43PM -0400, Jeremy Kister wrote: I'm stumped on how to sort an array based on a hash refrences's key in each element of my array. this is dumbed down code of what I have: my @array; while(my $row = $sth-fetchrow_arrayref){ my %hash = (id = $row-[0], name =

RE: sorting array full of hash references

2005-06-07 Thread Charles K. Clarkson
Jeremy Kister mailto:[EMAIL PROTECTED] wrote: : I'm stumped on how to sort an array based on a hash refrences's : key in each element of my array. : : this is dumbed down code of what I have: : my @array; : while(my $row = $sth-fetchrow_arrayref){ : my %hash = (id = $row-[0], name = $row-[1]);

hash array sorting

2005-06-03 Thread Mike Blezien
Hello, ran into a strange problem when doing a sort. we have a file like this: 0::Accounts;Local Language 1::Anatomy;Local Language 2::Arabic;Local Language .. 26::German;Local Language 27::Governmentpolitics;Local Language . 3::Architecture;Local Language

Re: hash array sorting

2005-06-03 Thread Sean Davis
Look at using lc (lower case). It can make your sort case-insensitive. On Jun 3, 2005, at 7:17 PM, Mike Blezien wrote: Hello, ran into a strange problem when doing a sort. we have a file like this: 0::Accounts;Local Language 1::Anatomy;Local Language 2::Arabic;Local Language

Re: hash array sorting

2005-06-03 Thread Mike Blezien
How that apply to our code: foreach $key (sort { $lang-{$a}-[0] cmp $lang-{$b}-[0] } keys(%{$lang})) { # do stuff here } Sean Davis wrote: Look at using lc (lower case). It can make your sort case-insensitive. On Jun 3, 2005, at 7:17 PM, Mike Blezien wrote: Hello, ran into

<    1   2   3   4   5   6   7   >