Re: having trouble understanding the built-in Perl sort with regards to mixed numbers and strings

2016-06-28 Thread David Precious
On Fri, 17 Jun 2016 14:33:12 -0700 Kenneth Wolcott wrote: > Hi; > > I'm having trouble understanding the built-in Perl sort with regards > to mixed numbers and strings > > I'm looking at http://perldoc.perl.org/functions/sort.html > > I have a

Re: having trouble understanding the built-in Perl sort with regards to mixed numbers and strings

2016-06-20 Thread Kenneth Wolcott
compare" routine uses $a and $b which are "special" to perl >> sort routines. >> Also the compare routine is written for obviousness rather than for brevity >> or elegance. >> >> The return from compare illustrates Shalomi Fish's point about usi

Re: having trouble understanding the built-in Perl sort with regards to mixed numbers and strings

2016-06-20 Thread Shlomi Fish
Hi Chris, On Mon, 20 Jun 2016 11:28:57 -0600 Chris Fedde wrote: > Kenneth, > > Below the cut is my example implementation as I understand your > requirements. > Note that the "compare" routine uses $a and $b which are "special" to perl > sort routines. >

Re: having trouble understanding the built-in Perl sort with regards to mixed numbers and strings

2016-06-20 Thread Chris Fedde
Kenneth, Below the cut is my example implementation as I understand your requirements. Note that the "compare" routine uses $a and $b which are "special" to perl sort routines. Also the compare routine is written for obviousness rather than for brevity or elegance. The

Re: having trouble understanding the built-in Perl sort with regards to mixed numbers and strings

2016-06-18 Thread Shlomi Fish
Hi Kenneth, On Fri, 17 Jun 2016 14:41:41 -0700 Kenneth Wolcott wrote: > On Fri, Jun 17, 2016 at 2:33 PM, Kenneth Wolcott > wrote: > > Hi; > > > > I'm having trouble understanding the built-in Perl sort with regards > > to mixed numbers and st

Re: having trouble understanding the built-in Perl sort with regards to mixed numbers and strings

2016-06-17 Thread Brock Wilcox
In this very particular case you should consider turning off the warning, maybe limiting it to the block. On Jun 17, 2016 5:42 PM, "Kenneth Wolcott" wrote: > On Fri, Jun 17, 2016 at 2:33 PM, Kenneth Wolcott > wrote: > > Hi; > > > > I'm having trouble un

Re: having trouble understanding the built-in Perl sort with regards to mixed numbers and strings

2016-06-17 Thread Jim Gibson
If you want to sort your data numerically, then the data must look like a number. Your data is mixed numerical and alpha data, hence the error message. You first need to extract the numerical parts of your data records and compare just those parts. The first step would be to write a sort

Re: having trouble understanding the built-in Perl sort with regards to mixed numbers and strings

2016-06-17 Thread Kenneth Wolcott
On Fri, Jun 17, 2016 at 2:33 PM, Kenneth Wolcott wrote: > Hi; > > I'm having trouble understanding the built-in Perl sort with regards > to mixed numbers and strings > > I'm looking at http://perldoc.perl.org/functions/sort.html > > I have an array that I w

having trouble understanding the built-in Perl sort with regards to mixed numbers and strings

2016-06-17 Thread Kenneth Wolcott
Hi; I'm having trouble understanding the built-in Perl sort with regards to mixed numbers and strings I'm looking at http://perldoc.perl.org/functions/sort.html I have an array that I want to have sorted numerically and descending. The array is composed of elements that loo

Re: Perl sort for reverse numeric if numbers and text are in a string, numbers first

2016-03-09 Thread Brock Wilcox
Probably you have "use warnings" turned on. You can disable the warning for numeric comparison with "no warnings 'numeric';" perl -E 'use warnings; no warnings "numeric"; my @a = ("12\thi","37\tb","123\tc","187\ta&quo

Re: Perl sort for reverse numeric if numbers and text are in a string, numbers first

2016-03-08 Thread Shawn H Corey
On Tue, 8 Mar 2016 13:29:40 -0800 Kenneth Wolcott wrote: > How do I call the built-in Perl sort function on an array of strings > where the string is composed of one or more digits, followed by a tab > which is followed by a string and I want the results to be sorted in > reverse n

Re: Perl sort for reverse numeric if numbers and text are in a string, numbers first

2016-03-08 Thread Andrew Solomon
> Hi; > > How do I call the built-in Perl sort function on an array of strings > where the string is composed of one or more digits, followed by a tab > which is followed by a string and I want the results to be sorted in > reverse numeric order? > > I looked at http

Perl sort for reverse numeric if numbers and text are in a string, numbers first

2016-03-08 Thread Kenneth Wolcott
Hi; How do I call the built-in Perl sort function on an array of strings where the string is composed of one or more digits, followed by a tab which is followed by a string and I want the results to be sorted in reverse numeric order? I looked at http://perldoc.perl.org/functions/sort.html

Re: How to sort a file based on numerical values exists in each line

2015-03-24 Thread Jim Gibson
u can see in my code there is no hard coded value. You can modify the regular expression used to extract the sort values depending upon the circumstances under which your function will be used. I was just giving an example of how to combine all of the individual steps into one command. I based the

Re: How to sort a file based on numerical values exists in each line

2015-03-24 Thread Anirban Adhikary
:MO=RXOTRX-473-5,SC=0,DCP1=223,SIG=SCCONC,DCP2=224&&231,TEI=5; > > RXMOI:MO=RXOTRX-473-1,SC=0,DCP1=187,SIG=SCCONC,DCP2=188&&195,TEI=1; > ... > > > This file is from a testing environment. But in production environment > this file can be more than 500 lines. So m

Re: How to sort a file based on numerical values exists in each line

2015-03-24 Thread Simon Reinhardt
Am 24.03.2015 um 14:03 schrieb Shlomi Fish: > This can be more idiomatically written as: > > $a->[1] <=> $b->[1] or $a->[2] <=> $b->[2] I agree, a sort { $a->[0] <=> $b->[0] or $a->[1] <=> $b->[1] or $a->[2] <

Re: How to sort a file based on numerical values exists in each line

2015-03-24 Thread Jim Gibson
-473-1,SC=0,DCP1=187,SIG=SCCONC,DCP2=188&&195,TEI=1; ... > This file is from a testing environment. But in production environment this > file can be more than 500 lines. So my goal is to sort the file based on the > bold numbers and create a new file. > This is required for da

Re: How to sort a file based on numerical values exists in each line

2015-03-24 Thread Shlomi Fish
Hi Simon, thanks for helping Anirban, but I have a small comment about your code: On Tue, 24 Mar 2015 13:11:56 +0100 Simon Reinhardt wrote: > Hi Anirban, > > first we have to be clear how you want to sort the lines. > Does 10-1 sort before 1-11 ? > Do you want numeric (use <

Re: How to sort a file based on numerical values exists in each line

2015-03-24 Thread Simon Reinhardt
Hi Anirban, first we have to be clear how you want to sort the lines. Does 10-1 sort before 1-11 ? Do you want numeric (use <=>) or alphabetic (use cmp) order? > while (my $line = <$RFH>) { > chomp($line); > if ($line =~ m/.*?\-(\d+)\-(\d+).*/) { >

Re: How to sort a file based on numerical values exists in each line

2015-03-24 Thread Shaji Kalidasan
>) { chomp; my($val) = split ',', $_; #split the data using comma my($key, $value) = split '=', $val; #split the values using equal sign (=) $value =~ /.*?-([\d\-]+)$/; #extract the numbers following the pattern (-DIGIT-DIGIT) $data{$1} = $_; } #sort in a

Re: How to sort a file based on numerical values exists in each line

2015-03-24 Thread Shaji Kalidasan
lit '=', $val; #split the values using equal sign (=) $value =~ /.*?-([\d\-]+)$/; #extract the numbers following the pattern (-DIGIT-DIGIT) push @data, $1; } #sort in ascending order @data = sort {$a cmp $b} @data; print join "\n", @data; [/code] [data.txt] RXMOI:MO=RXOTR

Re: How to sort a file based on numerical values exists in each line

2015-03-24 Thread Anirban Adhikary
line); if ($line =~ m/.*?\-(\d+)\-(\d+).*/) { $sequence_no = "$1$2"; # print "$sequence_no-- $line\n"; $file_content_hash{$sequence_no}="$line"; } } for my $key ( sort {$a<=>$b} keys %file_conte

How to sort a file based on numerical values exists in each line

2015-03-24 Thread Anirban Adhikary
O=RXOTRX-*460-1*,SC=0,DCP1=187,SIG=SCCONC,DCP2=188&&195,TEI=1; RXMOI:MO=RXOTRX-*460-0*,SC=0,DCP1=178,SIG=SCCONC,DCP2=179&&186,TEI=0; This file is from a testing environment. But in production environment this file can be more than 500 lines. So my goal is to sort the file based

Re: arbitrary sort

2014-03-26 Thread Dr.Ruud
On 2014-03-26 12:36, shawn wilson wrote: return sort { return $pre->{$a} <=> $pre->{$b} if $pre->{$a} && $pre->{$b}; return -1 if $pre->{$a}; return +1 if $pre->{$b}; return $a cmp $b; } @$data; } Benchmark-a

Re: arbitrary sort

2014-03-26 Thread shawn wilson
Thanks guys: # Preceed sort with possible presorted values from an array. sub _sortpre { my ($self, $data, $prevals) = @_; my $i = 1; my $pre = (ref($prevals) eq 'ARRAY' and scalar(@$prevals) ? {map {$_ => $i++} @$prevals} : {} ); return sort { return $pre-&

Re: arbitrary sort

2014-03-25 Thread Uri Guttman
1, third => 1); And then the output becomes: Sorted: first, second, third, bar, baz, foo Which isn't correct. I humbly beg to differ. Your specification was to sort ‘first’, ‘second’, or ‘third’ before other keys, and the solution I provided does exactly that, sorting ‘first’, ‘secon

Re: arbitrary sort

2014-03-25 Thread Jim Gibson
=> 1); > > And then the output becomes: > Sorted: first, second, third, bar, baz, foo > > Which isn't correct. I humbly beg to differ. Your specification was to sort ‘first’, ‘second’, or ‘third’ before other keys, and the solution I provided does exactly that, sorting ‘first’, ‘s

Re: arbitrary sort

2014-03-25 Thread Jim Gibson
On Mar 25, 2014, at 6:55 AM, shawn wilson wrote: > i want to sort an array for certain key words first and then alphabetically. > > my @foo = qw/foo bar baz first second third/; > > foreach my $i (sort {$a cmp $b} @foo) { > print "$i\n"; > } > > How do

Re: arbitrary sort

2014-03-25 Thread shawn wilson
h isn't correct. On Tue, Mar 25, 2014 at 10:45 AM, Shawn H Corey wrote: > On Tue, 25 Mar 2014 09:55:25 -0400 > shawn wilson wrote: > >> i want to sort an array for certain key words first and then >> alphabetically. >> >> my @foo = qw/foo bar baz f

Re: arbitrary sort

2014-03-25 Thread Shawn H Corey
On Tue, 25 Mar 2014 09:55:25 -0400 shawn wilson wrote: > i want to sort an array for certain key words first and then > alphabetically. > > my @foo = qw/foo bar baz first second third/; > > foreach my $i (sort {$a cmp $b} @foo) { > print "$i\n"; > } > &

Re: arbitrary sort

2014-03-25 Thread Shlomi Fish
Hi Shawn, On Tue, 25 Mar 2014 09:55:25 -0400 shawn wilson wrote: > i want to sort an array for certain key words first and then alphabetically. > > my @foo = qw/foo bar baz first second third/; > > foreach my $i (sort {$a cmp $b} @foo) { > print "$i\n"; &

arbitrary sort

2014-03-25 Thread shawn wilson
i want to sort an array for certain key words first and then alphabetically. my @foo = qw/foo bar baz first second third/; foreach my $i (sort {$a cmp $b} @foo) { print "$i\n"; } How do I make 'first', 'second', and 'third' come before the rest? (I

Re: use sort error

2012-07-05 Thread Jim Gibson
iginal program had {} around the inner elements, not (), which made it an array of hash references. > print values($_) for sort my_sort @AoH; sub my_sort { > values($a)<=>values($b)} > ' > code > end

Re: use sort error

2012-07-05 Thread xiyoulaoyuanjia
one element. and i modify this to below code begin--- perl -e ' @AoH = ( ( rsh => "0.4", ), ( telnet=> "0.022", ), ( ssh => "0.3&qu

Re: use sort error

2012-07-05 Thread Shlomi Fish
Hi xiyoulaoyuanjia, On Thu, 5 Jul 2012 22:53:03 +0800 xiyoulaoyuanjia wrote: > hi: > > i want sort my array .but the result is not right. i did not know why ? > > ---begin > code-- >

use sort error

2012-07-05 Thread xiyoulaoyuanjia
hi: i want sort my array .but the result is not right. i did not know why ? ---begin code-- perl -e ' @AoH = ( { rsh => "0.4", }, { telnet=> "0.022",

Re: hash sort on value

2012-07-03 Thread Chris Stinemetz
On Tue, Jul 3, 2012 at 6:44 AM, Chris Stinemetz wrote: > On Tue, Jul 3, 2012 at 5:11 AM, xiyoulaoyuanjia > wrote: >> hi Rob 。 i do not know what the 'for' meaning inprint $_->[0], "\n" for >> sort { $b->[1] <=> $a->[1] } @RNC; >&g

Re: hash sort on value

2012-07-03 Thread Chris Stinemetz
On Tue, Jul 3, 2012 at 5:11 AM, xiyoulaoyuanjia wrote: > hi Rob 。 i do not know what the 'for' meaning inprint $_->[0], "\n" for > sort { $b->[1] <=> $a->[1] } @RNC; > can you give me mush information about this use 。 > 3ks ! > I belie

Re: hash sort on value

2012-07-02 Thread Chris Stinemetz
> > I believe you want the output lines formatted as they are but sorted in > descending order of the ec_count value, is that right? > > I suggest that, instead of printing the data straight from the hash you > store the lines in an array and sort it before displaying the informa

Re: hash sort on value

2012-07-02 Thread Rob Dixon
On 02/07/2012 17:42, Chris Stinemetz wrote: I have a 3 deminsional hash that I would like to sort on the value in descending order. I can't quite seem to figure it out The portion of the program I can't get figured out: ## body foreach my $frameNo ( keys %RNC ) { foreach my $ec ( k

Re: hash sort on value

2012-07-02 Thread David Precious
On Mon, 2 Jul 2012 11:42:44 -0500 Chris Stinemetz wrote: > I have a 3 deminsional hash that I would like to sort on the value in > descending order. I can't quite seem to figure it out > > The portion of the program I can't get figured out: > ## body > for

hash sort on value

2012-07-02 Thread Chris Stinemetz
I have a 3 deminsional hash that I would like to sort on the value in descending order. I can't quite seem to figure it out The portion of the program I can't get figured out: ## body foreach my $frameNo ( keys %RNC ) { foreach my $ec ( keys %{$RNC{$frameNo}} ) { my $ec_co

Re: sort and count match in file

2012-04-17 Thread Uri Guttman
On 04/16/2012 01:58 AM, Shekar wrote: if( exists $hash_val{$dom} ) { my $val=$hash_val{$dom}; $val++; $hash_val{$dom}=$val; } else { $hash_val{$dom}=1; } all that code can be replaced with this one line: $hash_val{$dom}++ ; pe

Re: sort and count match in file

2012-04-16 Thread Rob Dixon
split / /,$text; @sort = ($arr1[3],$arr1[4]); say "$sort[0] => $sort[1]"; } result test:dom1 => CRIT test:dom2 => CRIT work:dom1 => CRIT test:dom1 => CRIT test:dom2 => CRIT work:dom1 => CRIT But, I need count of CRIT. I try $hash{$_}++ for

Re: sort and count match in file

2012-04-16 Thread Shekar
Thanks Uri, and Ruud for lightening up :) Cheers, Shekar On Mon, Apr 16, 2012 at 12:25 PM, Dr.Ruud wrote: > On 2012-04-16 07:58, Shekar wrote: > > next if (/^\s$/); >> > > You probably meant: > > next if /^\s*$/; # skip blank lines > > -- > Ruud > > > -- > To unsubscribe, e-mail: begin

Re: sort and count match in file

2012-04-15 Thread Dr.Ruud
On 2012-04-16 07:58, Shekar wrote: next if (/^\s$/); You probably meant: next if /^\s*$/; # skip blank lines -- Ruud -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/

Re: sort and count match in file

2012-04-15 Thread Uri Guttman
On 04/16/2012 01:58 AM, Shekar wrote: if( exists $hash_val{$dom} ) { my $val=$hash_val{$dom}; $val++; $hash_val{$dom}=$val; } else { $hash_val{$dom}=1; } all that code can be replaced with this one line: $hash_val{$dom}++ ; pe

Re: sort and count match in file

2012-04-15 Thread Shekar
rk:dom1 - count of CRIT(6) > > > File in .gz format > > my code > > #!/usr/bin/perl > > use strict; > use warnings; > use diagnostics; > use 5.010; > > use IO::Compress::Gzip; > use IO::Uncompress::Gunzip; > > my $file = "log.gz";

Re: sort and count match in file

2012-04-15 Thread John W. Krahn
'strict' enabled your program would have ended here because of the @arr variable. At this point @arr will only contain lines that have the pattern 'work' in them. foreach my $text (@arr) { @arr1 = split / /,$text; @sort = ($arr1[3],$arr1[4]); With 

Re: sort and count match in file

2012-04-15 Thread Shawn H Corey
ip>; foreach my $text (@arr) { @arr1 = split / /,$text; @sort = ($arr1[3],$arr1[4]); say "$sort[0] => $sort[1]"; $count{$sort[0]}{$sort[1]} ++; } for my $k1 ( keys %count ){ for my $k2 ( keys %{ $count{$k1} }){ print "$k1

sort and count match in file

2012-04-15 Thread Вячеслав Агапов
warnings; use diagnostics; use 5.010; use IO::Compress::Gzip; use IO::Uncompress::Gunzip; my $file = "log.gz"; my $ungzip = new IO::Uncompress::Gunzip($file); @arr = grep /work/, <$ungzip>; foreach my $text (@arr) { @arr1 = split / /,$text; @sort = ($arr1[3],$arr1[

Re: how to sort two array in perl

2011-10-16 Thread shawn wilson
On Sat, Oct 15, 2011 at 03:45, Lemon wrote: > Many thanks to Shlomi and Paul, > > > I need to read sort manual and map manual. > yes, that's a good place to start. but, just because i like being different and because i really enjoy the power of this simple little modul

Re: how to sort two array in perl

2011-10-16 Thread Lemon
Many thanks to Shlomi and Paul, Shlomi gave the solution for @array[@a,@b] (@a=(1, 7, 54, 2), @b(2, 89, 78, 33) ), for my case two array may be esay to deal with. I need to read sort manual and map manual. Meng Ni On Fri, Oct 14, 2011 at 11:16 PM, Paul Johnson wrote: > On Thu, Oct

Re: how to sort two array in perl

2011-10-14 Thread Paul Johnson
On Thu, Oct 13, 2011 at 02:39:52AM -0700, Lemon wrote: > Dear all, > > I want to sort data set like this > > (@a, @b) > 1,21,2 > 7,89=> 2,33 > 54,78

Re: how to sort two array in perl

2011-10-14 Thread Rob Coops
On Fri, Oct 14, 2011 at 4:32 PM, Shlomi Fish wrote: > On Thu, 13 Oct 2011 02:39:52 -0700 (PDT) > Lemon wrote: > > > Dear all, > > > > I want to sort data set like this > > > > (@a, @b) > > 1,21,2 > &g

Re: how to sort two array in perl

2011-10-14 Thread Shlomi Fish
On Thu, 13 Oct 2011 02:39:52 -0700 (PDT) Lemon wrote: > Dear all, > > I want to sort data set like this > > (@a, @b) > 1,21,2 > 7,89=> 2,33 > 54,78

how to sort two array in perl

2011-10-14 Thread Lemon
Dear all, I want to sort data set like this (@a, @b) 1,21,2 7,89=> 2,33 54,787,89 2,33 54,78 I know that linux command sort can

self referential arrays/hashes ? [sort]

2011-08-18 Thread shawn wilson
I'm wondering (as i faced this a week ago or so), how much memory does this take up (over the original data) ? and whether it's worth it (ie, does this save me anything over a sort)? and is there a better way to do this (if it doesn't take up much more memory and does save over a s

Re: sort hash

2011-06-23 Thread Irfan Sayed
thanks rob. it worked From: Rob Dixon To: beginners@perl.org Cc: Irfan Sayed Sent: Thursday, June 23, 2011 3:37 PM Subject: Re: sort hash On 23/06/2011 10:36, Irfan Sayed wrote: > Hi, > > i need to sort hash in descending order. > but the issue

Re: sort hash

2011-06-23 Thread Dr.Ruud
On 2011-06-23 11:36, Irfan Sayed wrote: [I need to sort a hash, but my keys are integers] Realize that all hash keys are strings. sort { $hash_fin{$b} <=> $hash_fin{$a} } keys %hash_fin You were almost there: sort { $b <=> $a } keys %hash_fin The <=> operator is

Re: sort hash

2011-06-23 Thread Rob Dixon
On 23/06/2011 10:36, Irfan Sayed wrote: > Hi, > > i need to sort hash in descending order. > but the issue is , in hash, i have key as integer value and the value > associated with that key is string > > so when i do sort it does not really sort the hash on the key

sort hash

2011-06-23 Thread Irfan Sayed
Hi, i need to sort hash in descending order. but the issue is , in hash, i have key as integer value and the value associated with that key is string so when i do sort it does not really sort the hash on the key level i used follwoing code foreach my $key (sort { $hash_fin{$b

Re: sort results in ascending order

2011-03-17 Thread Uri Guttman
d of help. I judged that Chris may well have RD> trouble with anonymous hashes and Schwartzian transforms and, as I RD> wrote, I believe it is important that software should be completely RD> understood by its author. you can also point out Sort::Maker which can do complex sorts with muc

Re: sort results in ascending order

2011-03-17 Thread Shawn H Corey
On 11-03-17 03:23 PM, Rob Dixon wrote: We have established that Chris's data is numeric. Your code is overkill. No, it's not. Just because this case does not have the join character in the data, does mean it will never happen. What the novice programmer is going to do is decide that this te

Re: sort results in ascending order

2011-03-17 Thread Rob Dixon
On 17/03/2011 18:43, Shawn H Corey wrote: On 11-03-17 02:04 PM, Rob Dixon wrote: A beginners list isn't the place to introduce arbitrarily complex Perl constructs. Replies have to be sensitive to the ability of the OP or they may co On the other hand, telling them to use a kluge to get the re

Re: sort results in ascending order

2011-03-17 Thread Shawn H Corey
On 11-03-17 02:04 PM, Rob Dixon wrote: A beginners list isn't the place to introduce arbitrarily complex Perl constructs. Replies have to be sensitive to the ability of the OP or they may co On the other hand, telling them to use a kluge to get the results they want is very bad advice. Tell t

Re: sort results in ascending order

2011-03-17 Thread Rob Dixon
On 17/03/2011 17:22, Shawn H Corey wrote: On 11-03-17 01:05 PM, Rob Dixon wrote: If you are uncomfortable with arrays of hash references Sooner or later every Perl programmer has to become comfortable with complex data structures. Why not start now? A beginners list isn't the place to intro

Re: sort results in ascending order

2011-03-17 Thread Rob Dixon
On 17/03/2011 17:22, Chris Stinemetz wrote: From: Rob Dixon [mailto:rob.di...@gmx.com] If you are uncomfortable with arrays of hash references, it may be better for you to create an array of records containing just the four fields you are interested in, and then sort that. Such a program is

Re: sort results in ascending order

2011-03-17 Thread Shawn H Corey
On 11-03-17 01:05 PM, Rob Dixon wrote: If you are uncomfortable with arrays of hash references Sooner or later every Perl programmer has to become comfortable with complex data structures. Why not start now? -- Just my 0.0002 million dollars worth, Shawn Confusion is the first step

Re: sort results in ascending order

2011-03-17 Thread Rob Dixon
On 16/03/2011 14:58, Chris Stinemetz wrote: > Shawn H Corey wrote: >> On 11-03-16 09:26 AM, Chris Stinemetz wrote: >>> >>> I would like to print results in ascending order starting with $cell, >>> $sect, and finally $carr. >> >> You would need

Re: sort results in ascending order

2011-03-17 Thread Chas. Owens
On Thu, Mar 17, 2011 at 11:04, Chris Stinemetz wrote: snip > For some reason I am not getting the sorted list in my output file. Instead I > am getting the following: > > bc8) HASH(0x100d0d78) HASH(0x100d15e8) HASH(0x100d0f28) HASH(0x100d0c58) > HASH(0x100d1168) HASH(0x100d1678) snip You are g

Re: sort results in ascending order

2011-03-17 Thread Shawn H Corey
On 11-03-17 11:04 AM, Chris Stinemetz wrote: print OUTFILE "@sorted:\n"; for my $tuple ( @sorted ){ print "$tuple->{cell} $tuple->{sect} $tuple->{carr} $tuple->{RTD}\n"; } -- Just my 0.0002 million dollars worth, Shawn Confusion is the first step of understanding. Pr

RE: sort results in ascending order

2011-03-17 Thread Chris Stinemetz
my($cell,$sect,$carr,$RTD) = ($data[31],$data[32],$data[38],$data[261]); push @array, { cell => $cell, sect => $sect, carr => $carr, RTD => $RTD,

Re: sort results in ascending order

2011-03-16 Thread Shawn H Corey
On 11-03-16 10:58 AM, Chris Stinemetz wrote: Where would I place print to see the results for validation? Since @sorted contains the sorted data, anywhere after it gets the sorted data. -- Just my 0.0002 million dollars worth, Shawn Confusion is the first step of understanding. Prog

RE: sort results in ascending order

2011-03-16 Thread Chris Stinemetz
Thanks, Where would I place print to see the results for validation? On 11-03-16 09:26 AM, Chris Stinemetz wrote: > I would like to print results in ascending order starting with $cell, $sect, > and finally $carr. You would need to store the data in a large array, then sort it. # un

Re: sort results in ascending order

2011-03-16 Thread Shawn H Corey
On 11-03-16 09:26 AM, Chris Stinemetz wrote: I would like to print results in ascending order starting with $cell, $sect, and finally $carr. You would need to store the data in a large array, then sort it. # untested due lack of data my @array = (); while (<>) { chomp;

sort results in ascending order

2011-03-16 Thread Chris Stinemetz
I would like to print results in ascending order starting with $cell, $sect, and finally $carr. I am getting the error: Name "main::a" used only once: possible typo at ./DOband.pl line 6. Name "main::b" used only once: possible typo at ./DOband.pl line 6. Below is my code. Any help is greatly a

Re: how smart is sort?

2010-12-15 Thread John
st_sort { for (0..$#$a) { $z=$$a[$_]<=>$$b[$_]; return $z if $z!=0 } return 0 } print "$$_[0],$$_[1]\n" for sort test_sort @array; Do all of your arrays only have one or two elements? Or is this just an example? This is just an example. I saw this

Re: how smart is sort?

2010-12-15 Thread John W. Krahn
John wrote: Thanks for pointing out the indexing mistake. I've fixed that in the code below, but the sorting is still correct. (I've also added "return 0" in case $z is always 0, but I get the same sort results with or without it.) The new array being sorted also shows tha

Re: how smart is sort?

2010-12-15 Thread John
ou trying to accomplish with that? } } print "$$_[0],$$_[1]\n" for sort my_sort @array; First I thought I needed "for" to run from 0 to the larger of the lengths of @$a and @$b, but with the example code, Perl sorts the entries correctly, even though "for"

Re: how smart is sort?

2010-12-14 Thread John W. Krahn
r ( 0 .. $#$a ) { return $x if 0!=($x=$$a[$_]<=>$$b[$_]) You are returning $x if $a->[$_] is not equal to $b->[$_], but if $a->[$_] *is* *equal* *to* $b->[$_] you are returning what? What exactly are you trying to accomplish with that? } } print "$$_[0

how smart is sort?

2010-12-14 Thread John
I'm sorting arrays by comparing corresponding entries. Take this example: @array = ([2,1],[2],[2,1],[1]); sub my_sort { for (0...@$a) { return $x if 0!=($x=$$a[$_]<=>$$b[$_]) } } print "$$_[0],$$_[1]\n" for sort my_sort @array; First I

Re: how to sort in perl where the key is the 2nd of 3 components of a string where a dash is the separator?

2010-07-23 Thread Dr.Ruud
marcos rebelo wrote: For doing the Sort, you may consider the schwartzian_transform sub schwartzian_transform(&@) { my $compute = shift; return map { $_->[1] } sort { $a->[0] cmp $b->[0] } map { [ $compute->(), $_ ] } @_; } schwartzian_transform { (

Re: how to sort in perl where the key is the 2nd of 3 components of a string where a dash is the separator?

2010-07-22 Thread marcos rebelo
bstrings. > > you should always show sample input data and expected output (sorted > data). just describing it even when simple can be different than the > actual data. > >  KW> I want to sort these space separated strings based on the middle of the >  KW> dash-separ

Re: how to sort in perl where the key is the 2nd of 3 components of a string where a dash is the separator?

2010-07-22 Thread Uri Guttman
(sorted data). just describing it even when simple can be different than the actual data. KW> I want to sort these space separated strings based on the middle of the KW> dash-separated substring. KW> The regex for the space-separated sub string is not exactly, but close to KW> th

how to sort in perl where the key is the 2nd of 3 components of a string where a dash is the separator?

2010-07-22 Thread Kenneth Wolcott
Hi; I have a legacy Perl script that I need to modify. The current output is a set of zero or more space separated strings where each substring is a string of of three dash-separated substrings. I want to sort these space separated strings based on the middle of the dash-separated substring

Re: sort hash in Data::Dumper

2010-06-20 Thread Chas. Owens
On Sun, Jun 20, 2010 at 04:41, philge philip wrote: > hi > > can someone tell me how i can sort by keys from a hash (huge data) stored > using Data::Dumper? snip Data::Dumper can be configured through the use of its package variables (or methods if you are using the OO version).

Re: sort hash in Data::Dumper

2010-06-20 Thread Shlomi Fish
On Sunday 20 Jun 2010 11:41:42 philge philip wrote: > hi > > can someone tell me how i can sort by keys from a hash (huge data) stored > using Data::Dumper? > You need to do: [code] my @keys = sort { $a cmp $b } keys(%hash); [/code] Is it causing a memory overflow? Regards,

sort hash in Data::Dumper

2010-06-20 Thread philge philip
hi can someone tell me how i can sort by keys from a hash (huge data) stored using Data::Dumper? thanking you philge

Re: sort hash with an array as the value

2010-05-11 Thread Shlomi Fish
Hi Owen, On Tuesday 11 May 2010 14:10:49 Owen wrote: > I have this statement; > > foreach my $key ( keys %filehash ) { > print "$key $filehash{$key}->[0]\t\t\t$filehash{$key}->[3]\t > $filehash{$key}->[2]\t $filehash{$key}->[1]\n"; > } > > but

AW: sort hash with an array as the value

2010-05-11 Thread Thomas Bätzler
Owen asked: > I have this statement; > > foreach my $key ( keys %filehash ) { > print "$key $filehash{$key}->[0]\t\t\t$filehash{$key}->[3]\t > $filehash{$key}->[2]\t $filehash{$key}->[1]\n"; > } > > but wish to sort the output by $filehash{

sort hash with an array as the value

2010-05-11 Thread Owen
I have this statement; foreach my $key ( keys %filehash ) { print "$key $filehash{$key}->[0]\t\t\t$filehash{$key}->[3]\t $filehash{$key}->[2]\t $filehash{$key}->[1]\n"; } but wish to sort the output by $filehash{$key}->[0]. Is it possible? How do I do this? I can&

Re: sort %hash by key

2009-12-07 Thread Shawn H Corey
Robert Wohlfarth wrote: > On Mon, Dec 7, 2009 at 10:29 PM, wrote: > >> I'm fairly new to perl but loving it. I've run into some trouble though... >> Trying to sort a hash by it's key value, which is not a problem by itself; >> >> foreach(my $key

Re: sort %hash by key

2009-12-07 Thread Robert Wohlfarth
On Mon, Dec 7, 2009 at 10:29 PM, wrote: > I'm fairly new to perl but loving it. I've run into some trouble though... > Trying to sort a hash by it's key value, which is not a problem by itself; > > foreach(my $key (sort keys %channels)) { >print $key; >

sort %hash by key

2009-12-07 Thread trapd00r
Hi, I'm fairly new to perl but loving it. I've run into some trouble though... Trying to sort a hash by it's key value, which is not a problem by itself; foreach(my $key (sort keys %channels)) { print $key; } What I've been struggling with for the last hour or so

Re: the classic "which is the fastest way to sort" question

2009-11-09 Thread Uri Guttman
of PP> keys. that is incorrect. it all depends on the growth of the algorithm. key extraction can be the same work as comparisons but it becomes O(N). note that with a straight call to sort() the comparison must also do key extraction. if the keys are just a list of strings or numbers, th

Re: the classic "which is the fastest way to sort" question

2009-11-09 Thread Philip Potter
2009/11/9 Michael Alipio : > Hi, >> >>  Do you need the fastest possible sort? > > I'm not even sure if I really need to worry about all these > sorting techniques. My program just reads a text file > (wordlist). It might be megabyte-sized or probably few &g

Re: the classic "which is the fastest way to sort" question

2009-11-09 Thread Shlomi Fish
On Monday 09 Nov 2009 19:40:29 Uri Guttman wrote: > >>>>> "MA" == Michael Alipio writes: > > MA> i'm planning to sort an input file (which was File::Slurp'ed, most > MA> likely megabyte-sized file) in various ways. I did some readings >

Re: the classic "which is the fastest way to sort" question

2009-11-09 Thread Michael Alipio
Hi,   > >  Do you need the fastest possible sort? I'm not even sure if I really need to worry about all these sorting techniques. My program just reads a text file (wordlist). It might be megabyte-sized or probably few gigabytes (i might also add size checking on this to be saf

Re: the classic "which is the fastest way to sort" question

2009-11-09 Thread Philip Potter
2009/11/9 Michael Alipio : > Hi, > > i'm planning to sort an input file (which was File::Slurp'ed, most likely > megabyte-sized file) in various ways. I did some readings and learned several > methods > that people have come up with in recent years. So to summarize,

  1   2   3   4   5   6   7   8   >