Re: Sorting a String

2011-08-17 Thread John W. Krahn
Shlomi Fish wrote: "Wagner, David --- Sr Programmer Analyst --- CFS" wrote: Since a \n is at end, then could use split like: for my $dtl ( sort {$a<=> $b} split(/\n/, $a_string) ) { One can also do split(/^/m, $a_string) to split into lines while preserving the newlines. It wi

Re: Sorting a String

2011-08-17 Thread Shlomi Fish
Hi, On Tue, 16 Aug 2011 11:09:35 -0500 "Wagner, David --- Sr Programmer Analyst --- CFS" wrote: > >-Original Message- > >From: Matt [mailto:lm7...@gmail.com] > >Sent: Tuesday, August 16, 2011 10:04 > >To: beginners@perl.org > >Subject: Sorting a String > > > >I believe you can sort an ar

RE: Sorting a String

2011-08-17 Thread Wagner, David --- Sr Programmer Analyst --- CFS
>-Original Message- >From: Matt [mailto:lm7...@gmail.com] >Sent: Tuesday, August 16, 2011 10:04 >To: beginners@perl.org >Subject: Sorting a String > >I believe you can sort an array like so: > >sort @my_array; > >I need to sort a string though. > >I have $a_string that contains: > >4565 lin

Re: Sorting a String

2011-08-16 Thread John W. Krahn
Matt wrote: I believe you can sort an array like so: sort @my_array; That should be: @my_array = sort @my_array; I need to sort a string though. I have $a_string that contains: 4565 line1 2345 line2 500 line3 etc. Obviously \n is at end of every line in the string. I need it sorted.

Re: Sorting a String

2011-08-16 Thread Brandon McCaig
On Tue, Aug 16, 2011 at 12:04 PM, Matt wrote: > I believe you can sort an array like so: > > sort @my_array; > > I need to sort a string though. > > I have $a_string that contains: > > 4565 line1 > 2345 line2 > 500 line3 > etc. > > Obviously \n is at end of every line in the string.  I need it sor

Re: Sorting a String

2011-08-16 Thread marcos rebelo
sort like string or like numbers? On Tue, Aug 16, 2011 at 18:04, Matt wrote: > I believe you can sort an array like so: > > sort @my_array; > > I need to sort a string though. > > I have $a_string that contains: > > 4565 line1 > 2345 line2 > 500 line3 > etc. > > Obviously \n is at end of every li

Re: Sorting an extremely LARGE file

2011-08-08 Thread shawn wilson
On Mon, Aug 8, 2011 at 10:10, Paul Johnson wrote: > On Mon, Aug 08, 2011 at 09:25:48AM -0400, shawn wilson wrote: >> On Aug 8, 2011 12:11 AM, "Ramprasad Prasad" wrote: >> > >> > Using the system linux sort ... Does not help. >> > On my dual quad core machine , (8 gb ram) sort -n file takes 10 >>

Re: Sorting an extremely LARGE file

2011-08-08 Thread Shawn H Corey
On 11-08-08 10:23 AM, Shlomi Fish wrote: I suggest splitting the files into bins. Each bin will contain the records with the batch numbers in a certain range (say 0-999,999 ; 1,000,000-1,999,999, etc.). You should select the bins so the numbers are spread more or less evenly. Then you sort each b

Re: Sorting an extremely LARGE file

2011-08-08 Thread Shlomi Fish
Hi Ramprasad, On Sun, 7 Aug 2011 20:58:14 +0530 Ramprasad Prasad wrote: > I have a file that contains records of customer interaction > The first column of the file is the batch number(INT) , and other columns > are date time , close time etc etc > > I have to sort the entire file in order of t

Re: Sorting an extremely LARGE file

2011-08-08 Thread Paul Johnson
On Mon, Aug 08, 2011 at 09:25:48AM -0400, shawn wilson wrote: > On Aug 8, 2011 12:11 AM, "Ramprasad Prasad" wrote: > > > > Using the system linux sort ... Does not help. > > On my dual quad core machine , (8 gb ram) sort -n file takes 10 > > minutes and in the end produces no output. > > I had a

Re: Sorting an extremely LARGE file

2011-08-08 Thread shawn wilson
On Aug 8, 2011 12:11 AM, "Ramprasad Prasad" wrote: > > Using the system linux sort ... Does not help. > On my dual quad core machine , (8 gb ram) sort -n file takes 10 > minutes and in the end produces no output. > I had a smaller file and 32g to play with on a dual quad core (dl320). Sort just c

Re: Sorting an extremely LARGE file

2011-08-08 Thread Paul Johnson
On Mon, Aug 08, 2011 at 10:40:12AM +0530, Ramprasad Prasad wrote: > Using the system linux sort ... Does not help. > On my dual quad core machine , (8 gb ram) sort -n file takes 10 > minutes and in the end produces no output. Did you set any other options? At a minimum you should set -T to tell

Re: Sorting an extremely LARGE file

2011-08-07 Thread Kenneth Wolcott
On Sun, Aug 7, 2011 at 22:10, Ramprasad Prasad wrote: > [snip] > I guess there is a serious need for re-architecting , rather than > create such monstrous files, but when people work with legacy systems > which worked fine when there was lower usage and now you tell then you > need a overhaul be

Re: Sorting an extremely LARGE file

2011-08-07 Thread Ramprasad Prasad
Using the system linux sort ... Does not help. On my dual quad core machine , (8 gb ram) sort -n file takes 10 minutes and in the end produces no output. when I put this data in mysql , there is an index on the order by field ... But I guess keys don't help when you are selecting the entire table.

Re: Sorting an extremely LARGE file

2011-08-07 Thread Uri Guttman
> "RP" == Rajeev Prasad writes: RP> hi, you can try this: first get only that field (sed/awk/perl) RP> whihc you want to sort on in a file. sort that file which i assume RP> would be lot less in size then your current file/table. then run a RP> loop on the main file using sorted file

Re: Sorting an extremely LARGE file

2011-08-07 Thread shawn wilson
On Sun, Aug 7, 2011 at 15:58, Rob Dixon wrote: > On 07/08/2011 20:30, Shawn H Corey wrote: >> >> On 11-08-07 03:20 PM, shawn wilson wrote: >>> >>> It can be sped up (slightly) with an index. >> >> Indexes in SQL don't normally speed up sorting. What they're best at is >> selecting a limited number

Re: Sorting an extremely LARGE file

2011-08-07 Thread Rob Dixon
On 07/08/2011 20:30, Shawn H Corey wrote: On 11-08-07 03:20 PM, shawn wilson wrote: It can be sped up (slightly) with an index. Indexes in SQL don't normally speed up sorting. What they're best at is selecting a limited number of records, usually less than 10% of the total. Otherwise, they ju

Re: Sorting an extremely LARGE file

2011-08-07 Thread Shawn H Corey
On 11-08-07 03:20 PM, shawn wilson wrote: It can be sped up (slightly) with an index. Indexes in SQL don't normally speed up sorting. What they're best at is selecting a limited number of records, usually less than 10% of the total. Otherwise, they just get in the way. The best you can do

Re: Sorting an extremely LARGE file

2011-08-07 Thread shawn wilson
On Aug 7, 2011 1:15 PM, "Paul Johnson" wrote: > > On Sun, Aug 07, 2011 at 08:58:14PM +0530, Ramprasad Prasad wrote: > > > I have a file that contains records of customer interaction > > The first column of the file is the batch number(INT) , and other columns > > are date time , close time etc etc

Re: Sorting an extremely LARGE file

2011-08-07 Thread Paul Johnson
On Sun, Aug 07, 2011 at 08:58:14PM +0530, Ramprasad Prasad wrote: > I have a file that contains records of customer interaction > The first column of the file is the batch number(INT) , and other columns > are date time , close time etc etc > > I have to sort the entire file in order of the first

Re: Sorting an extremely LARGE file

2011-08-07 Thread Rajeev Prasad
print $}' > tmp-file   sort   for id in `cat `;do grep $id >> sorted-large-file;done From: Ramprasad Prasad To: Shawn H Corey Cc: Perl Beginners Sent: Sunday, August 7, 2011 11:01 AM Subject: Re: Sorting an extremely LARGE file On 7 August 2011 21:24, Shawn H Corey wrote: >

Re: Sorting an extremely LARGE file

2011-08-07 Thread Dr.Ruud
On 2011-08-07 17:28, Ramprasad Prasad wrote: I have a file that contains records of customer interaction The first column of the file is the batch number(INT) , and other columns are date time , close time etc etc I have to sort the entire file in order of the first column .. but the problem is

Re: Sorting an extremely LARGE file

2011-08-07 Thread Ramprasad Prasad
On 7 August 2011 21:24, Shawn H Corey wrote: > On 11-08-07 11:46 AM, Ramprasad Prasad wrote: > >> I used a mysql database , but the order by clause used to hang the >> process indefinitely >> If I sort files in smaller chunks how can I merge them back ?? >> >> > Please use "Reply All" when respon

Re: Sorting an extremely LARGE file

2011-08-07 Thread Shawn H Corey
On 11-08-07 11:46 AM, Ramprasad Prasad wrote: I used a mysql database , but the order by clause used to hang the process indefinitely If I sort files in smaller chunks how can I merge them back ?? Please use "Reply All" when responding to a message on this list. You need two temporary files a

Re: Sorting an extremely LARGE file

2011-08-07 Thread Shawn H Corey
On 11-08-07 11:28 AM, Ramprasad Prasad wrote: I have a file that contains records of customer interaction The first column of the file is the batch number(INT) , and other columns are date time , close time etc etc I have to sort the entire file in order of the first column .. but the problem is

Re: sorting report

2011-02-01 Thread Rob Dixon
On 01/02/2011 14:02, Chris Stinemetz wrote: #!/usr/bin/perl use warnings; use strict; use IO::Handle; RAW->format_lines_per_page(100); # I will change this once I get strict pragma to work. format RAW_TOP = @|||

RE: sorting report

2011-02-01 Thread Chris Stinemetz
I bottom posted. Any help is greatly appreciated. Chris -Original Message- From: Chris Stinemetz [mailto:cstinem...@cricketcommunications.com] Sent: Tuesday, February 01, 2011 8:03 AM To: Shlomi Fish; beginners@perl.org Subject: RE: sorting report Shlomi, See far bottom for my

RE: sorting report

2011-02-01 Thread Chris Stinemetz
Shlomi, See far bottom for my updated code. Chris Stinemetz -Original Message- From: Shlomi Fish [mailto:shlo...@iglu.org.il] Sent: Tuesday, February 01, 2011 4:18 AM To: beginners@perl.org Cc: Chris Stinemetz Subject: Re: sorting report Hi Chris, a few comments on your code: On

Re: sorting report

2011-02-01 Thread Shlomi Fish
Hi Chris, a few comments on your code: On Tuesday 01 Feb 2011 06:43:43 Chris Stinemetz wrote: > I would like to sort my final report in the following order: > > $data[31],$data[32],$data[38] > > How would I add this into my following program to get the report sorted > this way? > > Thanks in a

Re: Sorting files in a directory, without using any OS specific command, ordered by modified timestamp

2010-12-01 Thread Mark
> On Dec 1, 7:31 am, jwkr...@shaw.ca ("John W. Krahn") wrote: > > Correction: > > my @sorted_files_in_directory = >      map $_->[ 1 ], >      sort { $a->[ 0 ] <=> $b->[ 0 ] } >      map { ( stat "$directory_name/$_" )[ 9 ], $_ } map { [ ( stat "$directory_name/$_" )[ 9 ], $_ ] } >    

Re: Sorting files in a directory, without using any OS specific command, ordered by modified timestamp

2010-12-01 Thread Shlomi Fish
On Wednesday 01 December 2010 16:57:07 John W. Krahn wrote: > Amit Saxena wrote: > > Hi all, > > { > > > > next if ( ( $filename eq "." ) or ( $filename eq ".." ) ); > > > > push ( @files_in_directory, $filename ); > > > > } > > Since all you are doing is populating t

Re: Sorting files in a directory, without using any OS specific command, ordered by modified timestamp

2010-12-01 Thread Shawn H Corey
On 10-12-01 09:57 AM, John W. Krahn wrote: Or just: print map( "$_\n", @files_in_directory ), "\n"; print map( "$_\n", @sorted_files_in_directory ), "\n"; -- Just my 0.0002 million dollars worth, Shawn Programming is as much about organization and communication as it is about coding.

Re: Sorting files in a directory, without using any OS specific command, ordered by modified timestamp

2010-12-01 Thread John W. Krahn
John W. Krahn wrote: Amit Saxena wrote: my @sorted_files_in_directory; @sorted_files_in_directory = sort { (stat($a))[9]<=> (stat($b))[9] } If you read the documentation for readdir you will see where it says: If you're planning to filetest the return values out of a "readdir", you'd better

Re: Sorting files in a directory, without using any OS specific command, ordered by modified timestamp

2010-12-01 Thread John W. Krahn
Amit Saxena wrote: Hi all, Hello, The following perl program, for sorting files in a directory, without using any OS specific command, ordered by modified timestamp is not working. Please help. *Perl Program* #!perl.exe use strict; use warnings; my $directory_name; print "This program pr

Re: Sorting files in a directory, without using any OS specific command, ordered by modified timestamp

2010-12-01 Thread Shawn H Corey
On 10-12-01 07:19 AM, Amit Saxena wrote: print "Sorted listing of files in<$directory_name> directory are as follows :-\n"; my $j; foreach $j ( @files_in_directory ) foreach $j ( @sorted_files_in_directory ) { print $j . "\n"; } print "\n"; -- Just my 0.0002 million dollars w

Re: sorting DB_File hash data

2010-06-21 Thread C.DeRykus
On Jun 20, 1:39 am, philg...@yahoo.com (philge philip) wrote: > hi > > can someone tell me how i can sort by keys from a hash (huge data) stored in > a DB_File? > You might try a merge-sort - check CPAN. Another possibility: re-write the existing DB_File to use a DB_Tree format which by default

Re: Sorting mixed alphanumerics

2009-10-18 Thread Rick Triplett
Many thanks to Scott, Shawn, Paul, Jenda, and Uri. I've learned something from each of you, and appreciate your taking the time to help! Rick -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/

Re: Sorting mixed alphanumerics

2009-10-14 Thread Jenda Krynicky
From: Shawn H Corey > Jenda Krynicky wrote: > > ST is an overkill if the extraction is simple. > > > > Especially if the number of items is fairly small. > > > > Actually if the extraction is really simple and the extracted key is > > not so small, than ST may perform worse than an ordinary so

RE: Sorting mixed alphanumerics

2009-10-14 Thread Hall, Scott
>-Original Message- >From: Rick Triplett [mailto:r...@reason.net] >Sent: Tuesday, October 13, 2009 12:09 PM >To: Perl Beginners >Subject: Sorting mixed alphanumerics > >I need to sort the keys in a hash. The keys are the question number >and the values are the student's answer. A numeric s

Re: Sorting mixed alphanumerics

2009-10-14 Thread Uri Guttman
> "SHC" == Shawn H Corey writes: SHC> Jenda Krynicky wrote: >> ST is an overkill if the extraction is simple. >> >> Especially if the number of items is fairly small. >> >> Actually if the extraction is really simple and the extracted key is >> not so small, than ST may perf

Re: Sorting mixed alphanumerics

2009-10-14 Thread Shawn H Corey
Jenda Krynicky wrote: > ST is an overkill if the extraction is simple. > > Especially if the number of items is fairly small. > > Actually if the extraction is really simple and the extracted key is > not so small, than ST may perform worse than an ordinary sort doing > the extraction within t

Re: Sorting mixed alphanumerics

2009-10-14 Thread Jenda Krynicky
Date sent: Wed, 14 Oct 2009 11:03:13 -0400 From: Shawn H Corey To: Rick Triplett Copies to: Perl Beginners Subject:Re: Sorting mixed alphanumerics > Rick Triplett wrote: > > I need to sort the keys in a

Re: Sorting mixed alphanumerics

2009-10-14 Thread Paul Johnson
On Tue, Oct 13, 2009 at 11:09:09AM -0500, Rick Triplett wrote: > I need to sort the keys in a hash. The keys are the question number and > the values are the student's answer. A numeric sort with <=> won't work > since retaking a missed question (say, 2) produces the new key, 2h with > its new a

Re: Sorting mixed alphanumerics

2009-10-14 Thread Shawn H Corey
Rick Triplett wrote: > I need to sort the keys in a hash. The keys are the question number and > the values are the student's answer. A numeric sort with <=> won't work > since retaking a missed question (say, 2) produces the new key, 2h with > its new answer. A representative hash might look like

Re: Sorting a hash to user needs

2009-07-08 Thread Chas. Owens
On Wed, Jul 8, 2009 at 15:09, "Alexander Müller" wrote: > Hi, > > I need an order for hash by user preferences. Because the criterion to order > the hash entries a not numerical and not should sorted alphabetical, I tried > following > > >   3 %hashToSort = ( >   4 "a" => "one", >   5 "b"

Re: sorting anonymous arrays inside arrays

2009-07-02 Thread Jim Gibson
On 7/2/09 Thu Jul 2, 2009 12:12 PM, "daem0n...@yahoo.com" scribbled: > > Hi, > > If I have a loop that for each run creates > > while (){ >   my $value =~ /^\d/; >   $myhash{$mykey}->{'subkey'} = $value; > } > > > Normally, if I only want to sort $myhash through it's values, I would do > s

Re: Sorting a file dynamically

2009-01-30 Thread Rob Dixon
Anirban Adhikary wrote: > Dear list > I want to sort a file which contains the following data. > > SUDIP,PQR,OFFICER,15000 > DIPAK,ABC,CLERK,7500 > CHANDAN,MNP,MANAGER,12000 > WASIM,PQR,CLERK,12000 > PROTIK,XYZ,MANAGER,14000 > DIPAK,XYZ,ADMIN,17000 > > > now I have written a program which will s

Re: Sorting an array by a substring of its members

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

Re: Sorting an array by a substring of its members

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

Re: Sorting an array by a substring of its members

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

Re: Sorting an array by a substring of its members

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

Re: Sorting an array by a substring of its members

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

Re: Sorting an array by a substring of its members

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

Re: Sorting an array by a substring of its members

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

Re: Sorting!

2008-08-03 Thread Rob Dixon
Gunwant Singh wrote: > Rob Dixon wrote: >> >> my @sorted = sort { >> my @a = split /:/, $a; >> my @b = split /:/, $b; >> $a[1] <=> $b[1]; >> } @list; >> >> print "$_\n" foreach @sorted; > > I got what your code says.Thanks a lot!! > Can you tell me what is $a[1] <=> $b[1] doing for me? It co

Re: Sorting!

2008-08-03 Thread Gunwant Singh
Rob Dixon wrote: Gunwant Singh wrote: Hi all, I really appreciate all you guys there for the help you've provided to me in the past. So here I am again with a Question. I have a file with the following entries: 1:17 4:3 4:11 4:13 11:16 12:10 13:2 19:5 20:7 26:12 28:4 33:15 33:17 35:9 36:

Re: Sorting!

2008-08-02 Thread Rob Dixon
Gunwant Singh wrote: > Hi all, > > I really appreciate all you guys there for the help you've provided to > me in the past. > So here I am again with a Question. > > I have a file with the following entries: > > 1:17 > 4:3 > 4:11 > 4:13 > 11:16 > 12:10 > 13:2 > 19:5 > 20:7 > 26:12 > 28:4 > 33:1

Re: Sorting!

2008-08-02 Thread Mr. Shawn H. Corey
On Sun, 2008-08-03 at 01:53 +0530, Gunwant Singh wrote: > Hi all, > > I really appreciate all you guys there for the help you've provided to > me in the past. > So here I am again with a Question. > > I have a file with the following entries: > > 1:17 > 4:3 > 4:11 > 4:13 > 11:16 > 12:10 > 13:2

Re: Sorting a hash

2008-06-03 Thread Matthew Whipple
On Mon, 2008-06-02 at 11:53 -0700, Iain Adams wrote: > Hello, > > I am trying to sort a hash of hashes. > > my code looks like this > > foreach $cnt (sort keys %{ $relations{ $uid }{ "instances" } }){ > print OUT "$cnt 1, "; > } > > This prints out the correct numbers (the keys

Re: Sorting a hash

2008-06-03 Thread Iain Adams
On Jun 2, 8:43 pm, [EMAIL PROTECTED] (Jialin Li) wrote: > On Mon, Jun 2, 2008 at 1:53 PM, Iain Adams <[EMAIL PROTECTED]> wrote: > > Hello, > > > I am trying to sort a hash of hashes. > > > my code looks like this > > >  foreach $cnt (sort keys %{ $relations{ $uid }{ "instances" } }){ > >          

Re: Sorting a hash

2008-06-02 Thread Rob Dixon
Iain Adams wrote: > Hello, > > I am trying to sort a hash of hashes. > > my code looks like this > > foreach $cnt (sort keys %{ $relations{ $uid }{ "instances" } }){ > print OUT "$cnt 1, "; > } > > This prints out the correct numbers (the keys of the instances hash. > However the

Re: Sorting a hash

2008-06-02 Thread Li, Jialin
On Mon, Jun 2, 2008 at 1:53 PM, Iain Adams <[EMAIL PROTECTED]> wrote: > Hello, > > I am trying to sort a hash of hashes. > > my code looks like this > > foreach $cnt (sort keys %{ $relations{ $uid }{ "instances" } }){ > print OUT "$cnt 1, "; > } > > This prints out the correct number

Re: Sorting and grouping question

2008-05-15 Thread Li, Jialin
On Thu, May 15, 2008 at 12:13 PM, ANJAN PURKAYASTHA < [EMAIL PROTECTED]> wrote: > Hi, > here is a problem I'm working on. It's not PERL-specific, rather it is a > problem in sorting followed by grouping. > Suppose I have a set of lines that have tab-delimited text, thus: > 1 w 3 wer > 2 a

Re: sorting speed

2007-09-10 Thread Chas Owens
On 9/10/07, Jeremy Kister <[EMAIL PROTECTED]> wrote: > I am trying to optimize some sorting code I have. The data structure is > as follows: > > my %hash = (x => [ 'a','b','c' ], > y => [ 'd','e' ], > z => [ 'f' ], > ); > > > The result I expect is simply the

Re: sorting speed

2007-09-10 Thread Jeremy Kister
On 9/10/2007 5:13 PM, Rob Dixon wrote: use List::Util qw/max/; my %hash = (x => [ 'a','b','c' ], y => [ 'd','e' ], z => [ 'f' ], ); my $most = max map scalar @$_, values %hash; Woah! That's fast! :) thanks, -- Jeremy Kister http://jeremy.kister.net./ --

Re: sorting speed

2007-09-10 Thread Rob Dixon
Jeremy Kister wrote: I am trying to optimize some sorting code I have. The data structure is as follows: my %hash = (x => [ 'a','b','c' ], y => [ 'd','e' ], z => [ 'f' ], ); The result I expect is simply the highest number of elements. In this case, the

Re: sorting speed

2007-09-10 Thread Jeremy Kister
On 9/10/2007 4:45 PM, Jeremy Kister wrote: if(@{$hash{$key}} > $highest){ oops, that's if(@{$hash{$key}} > $most){ not $highest. -- Jeremy Kister http://jeremy.kister.net./ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.

Re: Sorting the items in a directory

2007-04-27 Thread Nigel Peck
Thanks Jeff, thanks Rob. I used your solution Jeff and it's working a treat. Cheers, Nigel Rob Dixon wrote: Nigel Peck wrote: Hi, I have a list containing the names of all items in a directory. I want to sort it by non-directories first and then directories, with a secondary sort in alph

Re: Sorting the items in a directory

2007-04-27 Thread John W. Krahn
Nigel Peck wrote: > > Hi, Hello, > I have a list containing the names of all items in a directory. I want > to sort it by non-directories first and then directories, with a > secondary sort in alphabetical order. > > I currently have: > > > my @items = sort { >

Re: Sorting the items in a directory

2007-04-27 Thread Rob Dixon
Nigel Peck wrote: Hi, I have a list containing the names of all items in a directory. I want to sort it by non-directories first and then directories, with a secondary sort in alphabetical order. I currently have: my @items = sort { my $a_path = $a

Re: Sorting the items in a directory

2007-04-27 Thread Jeff Pang
I'm sorry that just be clear you want the non-directory first,then simply change the codes to: my @items = map { $_->[0] } sort { $a->[1] <=> $b->[1] or $a->[0] cmp $b->[0] } map { -d $_ ? [$_,1] : [$_,0] } readdir DIR; 2007/4/27, Jeff Pang <[EMAIL PROTECTED]>: 2007/4/27,

Re: Sorting the items in a directory

2007-04-27 Thread Jeff Pang
2007/4/27, Nigel Peck <[EMAIL PROTECTED]>: Hi, I have a list containing the names of all items in a directory. I want to sort it by non-directories first and then directories, with a secondary sort in alphabetical order. Hello, I've tested, this could work for you. my @items = map { $_->[0]

Re: Sorting dir output

2007-04-10 Thread John W. Krahn
John W. Krahn wrote: > Igor Sutton Lopes wrote: >> >>sub move_file { >> >># using -M is better than doing the calculation to obtain the >>difference >># from now and three days ago. >>return unless -M $_ < 3; > > Why not just use the modified( '>3' ) rule? Ok, modified( '>3' ) won't

Re: Sorting dir output

2007-04-10 Thread Chas Owens
On 4/10/07, John W. Krahn <[EMAIL PROTECTED]> wrote: Igor Sutton Lopes wrote: snip > return unless -M $_ < 3; Why not just use the modified( '>3' ) rule? snip There doesn't seem to be a performance issue either way: Raterule explict rule450/s -- -0% explict 450/s

Re: Sorting dir output

2007-04-10 Thread John W. Krahn
Igor Sutton Lopes wrote: > Sorry! I was testing and sent the last version -TextMate integrated > with Mail.app- :-( > > On Apr 10, 2007, at 4:40 PM, John W. Krahn wrote: > >> [...] >> Did you test this? Where do you distinguish between files "older >> than 3 days" >> and other files? Where is

Re: Sorting dir output

2007-04-10 Thread Igor Sutton Lopes
Sorry! I was testing and sent the last version -TextMate integrated with Mail.app- :-( On Apr 10, 2007, at 4:40 PM, John W. Krahn wrote: [...] Did you test this? Where do you distinguish between files "older than 3 days" and other files? Where is "name('trunk')" specified by the OP? Th

Re: Sorting dir output

2007-04-10 Thread John W. Krahn
Igor Sutton Lopes wrote: > > On Apr 10, 2007, at 3:27 PM, John W. Krahn wrote: > >> Craig Schneider wrote: >> >>> How could I exec a 'dir' command on a dos system and put the output in >>> an array, sort by date and the files that are older than 3 days be >>> moved into a folder called 'history

Re: Sorting dir output

2007-04-10 Thread Igor Sutton Lopes
Hi, On Apr 10, 2007, at 3:27 PM, John W. Krahn wrote: Craig Schneider wrote: Hi Guys Hello, How could I exec a 'dir' command on a dos system and put the output in an array, sort by date and the files that are older than 3 days be moved into a folder called 'history' # open the curre

Re: Sorting dir output

2007-04-10 Thread John W. Krahn
Craig Schneider wrote: > Hi Guys Hello, > How could I exec a 'dir' command on a dos system and put the output in > an array, sort by date and the files that are older than 3 days be moved > into a folder called 'history' # open the current directory opendir my $dh, '.' or die "Cannot open '.' $

Re: Sorting dir output

2007-04-10 Thread yaron
Hi, If you wish to select all files that are directly under given directory you can implement the following (in pure perl fashion): sub numerically { $b <=> $a;} $DIR = ; $THRESHOLD_IN_DAYS = 3; my %time_to_file; my $currTime = time(); #Store all file in hash with time as key. for each my $

Re: Sorting dir output

2007-04-10 Thread Ken Foskey
On Tue, 2007-04-10 at 13:19 +0200, Craig Schneider wrote: > Hi Guys > > How could I exec a 'dir' command on a dos system and put the output in > an array, sort by date and the files that are older than 3 days be moved > into a folder called 'history' Look at module File::Find this should be abl

Re: Sorting dir output

2007-04-10 Thread Jeff Pang
Don't know much about dos. But under unix you may got the files older than 3 days by this way, chdir '/the/path'; @files = grep { time - (stat)[9] > 24*60*60*3 } glob "*"; 2007/4/10, Craig Schneider <[EMAIL PROTECTED]>: Hi Guys How could I exec a 'dir' command on a dos system and put the out

Re: Sorting an Array of Arrays

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

Re: Sorting an Array of Arrays

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

Re: Sorting an Array of Arrays

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

Re: Sorting from subroutine call

2006-12-02 Thread Sergio Escalada
Yes! It was exactly what I was trying to do. I wasn't so wrong after all. Thanks you, Dani, your code helps me a lot :D 2006/12/2, D. Bolliger <[EMAIL PROTECTED]>: Sergio Escalada am Samstag, 2. Dezember 2006 15:41: > Thanks for replies. > > The purpouse of this mini-script is to list the rows

Re: Sorting from subroutine call

2006-12-02 Thread D. Bolliger
Sergio Escalada am Samstag, 2. Dezember 2006 15:41: > 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 pr

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

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

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 cou

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 cou

Re: Sorting from subroutine call

2006-12-02 Thread Lawrence Statton XE2/N1GAK
> 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; > }

Re: Sorting from subroutine call

2006-12-02 Thread W.P.Nijhof
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; If you really want to call it like this

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 che

Re: Sorting on HoHoH

2006-09-08 Thread Rob Dixon
Hardly Armchair wrote: > > Hello List, > > I have a data structure like so: > > %p_mod = { > 'A' => { > 'fingers' => { > '4' => 'ABSFMQS', > '5' => 'SMTFQNL', >}, >

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 just

Re: Sorting on HoHoH

2006-09-07 Thread John W. Krahn
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. > 'A' => { > 'fingers' => { > '

  1   2   3   4   >