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
On 15/04/2012 18:44, Вячеслав Агапов wrote: Hello all. I have a file with logs 2012-04-13 17:06:10,881 test:dom1 CRIT home 2012-04-13 17:06:10,882 work:dom1 CRIT home 2012-04-13 17:06:10,882 my:dom1 CRIT home 2012-04-13 17:06:10,881 test:dom2 CRIT home 2012-04-13 17:06:10,882 work:dom2 CRIT home

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
Below code might be helpful... Assuming you are passing log file as argument 1, and your values in log file are space delimited, use Data::Dumper; open my $fd, "<", "$ARGV[0]" or die $!; while(<$fd>) { next if (/^\s$/); my ($some_date, $some_time, $dom, $crt, $home)=split; i

Re: sort and count match in file

2012-04-15 Thread John W. Krahn
Вячеслав Агапов wrote: Hello all. Hello, I have a file with logs 2012-04-13 17:06:10,881 test:dom1 CRIT home 2012-04-13 17:06:10,882 work:dom1 CRIT home 2012-04-13 17:06:10,882 my:dom1 CRIT home 2012-04-13 17:06:10,881 test:dom2 CRIT home 2012-04-13 17:06:10,882 work:dom2 CRIT home 2012-04-1

Re: sort and count match in file

2012-04-15 Thread Shawn H Corey
On 12-04-15 01:44 PM, Вячеслав Агапов wrote: #!/usr/bin/perl use strict; use warnings; use diagnostics; use 5.010; use IO::Compress::Gzip; use IO::Uncompress::Gunzip; my %count = (); my $file = "log.gz"; my $ungzip = new IO::Uncompress::Gunzip($file); @arr = grep/work/,<$ungzip>; foreach

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 numeric, so casts it

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 level > > > i used follwoing

Re: sort results in ascending order

2011-03-17 Thread Uri Guttman
> "RD" == Rob Dixon writes: RD> 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 struct

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 sho

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 to store the data in a large array, then sort it. >>

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
Good day, Your help is greatly appreciated. Thanks 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) HASH(0x100d21 70) HASH(0x100d0ce

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. # untested du

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; if (/;/) {

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). For instance:

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, Shlomi Fi

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 wish to sort the output by $filehash{$key}->[0].

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 (sort keys %channels)) { >>print $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; > } > > What I've been struggling wit

Re: sort with special order

2009-07-24 Thread Chas. Owens
On Fri, Jul 24, 2009 at 11:01, Jo for lists and groups wrote: > How about this? Jo > > > > #!/usr/bin/perl > > use strict; > use warnings; > > my @list = qw/dog is a there/; > my @sortOrder = (3,1,2,0); > my @sorted; > foreach (@sortOrder) { push(@sorted,$list[$_]); } > > print "@sorted"; > exit; s

Re: sort with special order

2009-07-24 Thread Steve Bertrand
Steve Bertrand wrote: > Jo for lists and groups wrote: >> How about this? Jo > >> #!/usr/bin/perl >> >> use strict; >> use warnings; >> >> my @list = qw/dog is a there/; >> my @sortOrder = (3,1,2,0); >> my @sorted; >> foreach (@sortOrder) { push(@sorted,$list[$_]); } >> >> print "@sorted"; >> exit

Re: sort with special order

2009-07-24 Thread Steve Bertrand
Jo for lists and groups wrote: > How about this? Jo > #!/usr/bin/perl > > use strict; > use warnings; > > my @list = qw/dog is a there/; > my @sortOrder = (3,1,2,0); > my @sorted; > foreach (@sortOrder) { push(@sorted,$list[$_]); } > > print "@sorted"; > exit; ...or this: #!/usr/bin/perl use

RE: sort with special order

2009-07-24 Thread Jo for lists and groups
How about this? Jo #!/usr/bin/perl use strict; use warnings; my @list = qw/dog is a there/; my @sortOrder = (3,1,2,0); my @sorted; foreach (@sortOrder) { push(@sorted,$list[$_]); } print "@sorted"; exit; -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands

Re: sort with special order

2009-07-23 Thread Chas. Owens
On Fri, Jul 24, 2009 at 00:14, sys adm wrote: > Hi, > > When I got a word list, I want it to be sorted with special order. > for example, I got this array: > > ("dog","is","a","there"); > > I want the sorted result is: > > ("there","is","a","dog"); > > How to code it? Thank you. snip You need to s

Re: sort multiple hash reference by value

2009-05-12 Thread Rick
Chas. Owens wrote: On Tue, May 12, 2009 at 00:08, Rick wrote: snip It's very weird. I did verify that it is numeric values that I am comparing... also i am using warnings and strict as well and i get no warnings. can't figure out what's wrong. snip In cases like this it is best to try

Re: sort multiple hash reference by value

2009-05-11 Thread Chas. Owens
On Tue, May 12, 2009 at 00:08, Rick wrote: snip > It's very weird. I did verify that it is numeric values that I am > comparing... also i am using warnings and strict as well and i get no > warnings. > can't figure out what's wrong. snip In cases like this it is best to try to reproduce your prob

Re: sort multiple hash reference by value

2009-05-11 Thread Rick
John W. Krahn wrote: Rick wrote: John W. Krahn wrote: Rick wrote: should this not work? Based upon the code presented, it looks like the code it correct. I am finding out that Length is *NOT* being sorted correctly numerically... Of course we don't know the data stored in %in_array and %

Re: sort multiple hash reference by value

2009-05-10 Thread John W. Krahn
Rick wrote: John W. Krahn wrote: Rick wrote: should this not work? Based upon the code presented, it looks like the code it correct. I am finding out that Length is *NOT* being sorted correctly numerically... Of course we don't know the data stored in %in_array and %in_array_c so it is h

Re: sort multiple hash reference by value

2009-05-10 Thread Rick
John W. Krahn wrote: Rick wrote: should this not work? Based upon the code presented, it looks like the code it correct. I am finding out that Length is *NOT* being sorted correctly numerically... Of course we don't know the data stored in %in_array and %in_array_c so it is hard to say wh

Re: sort multiple hash reference by value

2009-05-10 Thread John W. Krahn
Rick wrote: should this not work? Based upon the code presented, it looks like the code it correct. I am finding out that Length is *NOT* being sorted correctly numerically... Of course we don't know the data stored in %in_array and %in_array_c so it is hard to say why it is not working th

Re: sort without ignoring hyphens

2008-04-04 Thread tc314
On Apr 2, 9:04 am, [EMAIL PROTECTED] (Matthew Whipple) wrote: > LC_ALL=C sort echo.txt > > > > [EMAIL PROTECTED] wrote: > > On Mar 29, 3:19 pm, [EMAIL PROTECTED] (John W. Krahn) wrote: > > >> [EMAIL PROTECTED] wrote: > > >>> When I do string comparisons in perl the strings seem to ignore the > >>>

Re: sort without ignoring hyphens

2008-04-02 Thread Matthew Whipple
LC_ALL=C sort echo.txt [EMAIL PROTECTED] wrote: On Mar 29, 3:19 pm, [EMAIL PROTECTED] (John W. Krahn) wrote: [EMAIL PROTECTED] wrote: When I do string comparisons in perl the strings seem to ignore the embedded hyphens. I want to sort strings assuming the 'dictionary' order of the char

Re: sort without ignoring hyphens

2008-04-01 Thread tc314
On Mar 29, 3:19 pm, [EMAIL PROTECTED] (John W. Krahn) wrote: > [EMAIL PROTECTED] wrote: > > When I do string comparisons in perl the strings seem to ignore the > > embedded hyphens. > > I want to sort strings assuming the 'dictionary' order of the chars is > > ASCII order: hypen, 0-9, A-Z. > > It a

Re: sort without ignoring hyphens

2008-04-01 Thread Dr.Ruud
[EMAIL PROTECTED] schreef: > John W. Krahn: >> It appears to work in Perl: >> >> $ perl -le'@x = qw[22 2-2 2-3 23 21]; print for sort @x' >> 2-2 >> 2-3 >> 21 >> 22 >> 23 > > I'm looking for the perl way of comparing strings. > > Your posted code 'diff says memory exhausted need help with perl >

Re: sort without ignoring hyphens

2008-03-31 Thread John W. Krahn
[EMAIL PROTECTED] wrote: On Mar 30, 10:57 pm, [EMAIL PROTECTED] (John W. Krahn) wrote: It appears to work in Perl: $ perl -le'@x = qw[22 2-2 2-3 23 21]; print for sort @x' 2-2 2-3 21 22 23 I'm looking for the perl way of comparing strings. Your posted code 'diff says memory exhausted need h

Re: sort without ignoring hyphens

2008-03-31 Thread tc314
On Mar 31, 11:44 am, [EMAIL PROTECTED] (Dr.Ruud) wrote: > [EMAIL PROTECTED] schreef: > > > unsorted: > > 22 > > 2-2 > > 2-3 > > 23 > > 21 > > > linux sort produces: > > 21 > > 22 > > 2-2 > > 23 > > 2-3 > > $ echo ' > 21 > 22 > 2-4 > 2-2 > 23 > 2-3 > ' |sort -n > > 2-2 > 2-3 > 2-4 > 21 > 22 > 23 > >

Re: sort without ignoring hyphens

2008-03-31 Thread tc314
On Mar 30, 10:57 pm, [EMAIL PROTECTED] (John W. Krahn) wrote: > [EMAIL PROTECTED] wrote: > > > On Mar 29, 4:19 pm, [EMAIL PROTECTED] (John W. Krahn) wrote: > > >> [EMAIL PROTECTED] wrote: > > >>> When I do string comparisons in perl the strings seem to ignore the > >>> embedded hyphens. > >>> I wan

Re: sort without ignoring hyphens

2008-03-31 Thread Dr.Ruud
[EMAIL PROTECTED] schreef: > unsorted: > 22 > 2-2 > 2-3 > 23 > 21 > > linux sort produces: > 21 > 22 > 2-2 > 23 > 2-3 $ echo ' 21 22 2-4 2-2 23 2-3 ' |sort -n 2-2 2-3 2-4 21 22 23 -- Affijn, Ruud "Gewoon is een tijger." -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands,

Re: sort without ignoring hyphens

2008-03-30 Thread John W. Krahn
[EMAIL PROTECTED] wrote: On Mar 29, 4:19 pm, [EMAIL PROTECTED] (John W. Krahn) wrote: [EMAIL PROTECTED] wrote: When I do string comparisons in perl the strings seem to ignore the embedded hyphens. I want to sort strings assuming the 'dictionary' order of the chars is ASCII order: hypen, 0-9,

Re: sort without ignoring hyphens

2008-03-30 Thread tc314
On Mar 29, 4:19 pm, [EMAIL PROTECTED] (John W. Krahn) wrote: > [EMAIL PROTECTED] wrote: > > When I do string comparisons in perl the strings seem to ignore the > > embedded hyphens. > > I want to sort strings assuming the 'dictionary' order of the chars is > > ASCII order: hypen, 0-9, A-Z. > > It a

Re: sort without ignoring hyphens

2008-03-29 Thread John W. Krahn
[EMAIL PROTECTED] wrote: When I do string comparisons in perl the strings seem to ignore the embedded hyphens. I want to sort strings assuming the 'dictionary' order of the chars is ASCII order: hypen, 0-9, A-Z. It appears linux sort also has the problem (LC_ALL is blank). Any ideas? I want to av

Re: sort without ignoring hyphens

2008-03-29 Thread Rob Dixon
[EMAIL PROTECTED] wrote: > When I do string comparisons in perl the strings seem to ignore the embedded hyphens. > I want to sort strings assuming the 'dictionary' order of the chars is ASCII order: hypen, 0-9, A-Z. > It appears linux sort also has the problem (LC_ALL is blank). > Any ideas?

Re: Sort + Use of uninitialized value

2007-04-25 Thread Rob Dixon
yitzle wrote: P.S. What's HTH? Hope This Helps :) Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/

Re: Sort + Use of uninitialized value

2007-04-25 Thread yitzle
In that case just create a list of the keys with a defined VAL value before you do the sort: my @keys = grep defined $dHash{$_}{VAL}, keys %dHash; foreach (sort { $dHash{$b}{VAL} <=> $dHash{$a}{VAL} } @keys) { print $_, "\n"; } HTH, Rob This solution appeals to me. I'll use it. Tha

Re: Sort + Use of uninitialized value

2007-04-25 Thread Rob Dixon
yitzle wrote: Inside the loop I check if the value is defined, so I don't care where in the order the undefined one shows up in. I don't want to delete undefined ones or anything... On 4/25/07, Chas Owens <[EMAIL PROTECTED]> wrote: On 4/25/07, yitzle <[EMAIL PROTECTED]> wrote: > Warning messag

Re: Sort + Use of uninitialized value

2007-04-25 Thread Rob Dixon
yitzle wrote: On 4/25/07, Chas Owens <[EMAIL PROTECTED]> wrote: On 4/25/07, yitzle <[EMAIL PROTECTED]> wrote: Warning message: Use of uninitialized value in numeric comparison (<=>) at ... Code: foreach (sort { $dHash{$b}{'VAL} <=> $dHash{$a}{'VAL'} } keys %dHash) { How do I fix? Should my

Re: Sort + Use of uninitialized value

2007-04-25 Thread Chas Owens
On 4/25/07, yitzle <[EMAIL PROTECTED]> wrote: Inside the loop I check if the value is defined, so I don't care where in the order the undefined one shows up in. I don't want to delete undefined ones or anything... Then you can either turn off the warnings for that section (not advised), ignore

Re: Sort + Use of uninitialized value

2007-04-25 Thread Tom Phoenix
On 4/24/07, yitzle <[EMAIL PROTECTED]> wrote: Warning message: Use of uninitialized value in numeric comparison (<=>) at ... Code: foreach (sort { $dHash{$b}{'VAL} <=> $dHash{$a}{'VAL'} } keys %dHash) { How do I fix? Give it an initialized value. Maybe like this? sort { ($dHash{$b}{VAL} ||

Re: Sort + Use of uninitialized value

2007-04-25 Thread yitzle
Inside the loop I check if the value is defined, so I don't care where in the order the undefined one shows up in. I don't want to delete undefined ones or anything... On 4/25/07, Chas Owens <[EMAIL PROTECTED]> wrote: On 4/25/07, yitzle <[EMAIL PROTECTED]> wrote: > Warning message: > Use of uni

Re: Sort + Use of uninitialized value

2007-04-25 Thread Chas Owens
On 4/25/07, yitzle <[EMAIL PROTECTED]> wrote: Warning message: Use of uninitialized value in numeric comparison (<=>) at ... Code: foreach (sort { $dHash{$b}{'VAL} <=> $dHash{$a}{'VAL'} } keys %dHash) { How do I fix? Should my sort function be checking for variable defined? What do I return on

Re: Sort + Use of uninitialized value

2007-04-24 Thread Owen Cook
On Wed, Apr 25, 2007 at 01:37:24AM -0400, yitzle wrote: > Warning message: > Use of uninitialized value in numeric comparison (<=>) at ... > > Code: > foreach (sort { $dHash{$b}{'VAL} <=> $dHash{$a}{'VAL'} } keys %dHash) { perhaps foreach (sort { $dHash{$b}{'VAL'} <=> $dHash{$a

Re: sort and print multiple lines

2007-03-03 Thread Jeff Pang
>> >> Data file below is just made up but illustrates the structure >> >> line1^FC12345^IQ >> line1^FC12345^LD >> line1^FC2345^pq >> line2^FC12345^IQ >> line2^FC12345^LD >> line2^FC2345^pq >> line3^FC12345^IQ >> line3^FC12345^LD >> line3^FC2345^pq >> >> WHEN FINISHED >> line1 >> line2 >> line3 >>

Re: sort question

2006-12-13 Thread Jason Roth
Ok, for those interested the threshold for shuffling is 256 elements. Though I'm still confused on shuffling vs. random quicksort, I imagine thats a question only the person who implemented it can answer. And thanks for the clarification on lists vs arrays. On 12/13/06, John W. Krahn <[EMAIL PRO

Re: sort question

2006-12-13 Thread John W. Krahn
Jason Roth wrote: > I was reading the perldoc for the sort function and I had a few > questions. http://perldoc.perl.org/sort.html says that large arrays > will be shuffled to ensure nlgn runtime. What is the cutoff for > "large arrays" and is there a reason that it isn't simply using a > randomi

Re: Sort uniq

2006-10-19 Thread Dr.Ruud
Rob Dixon schreef: > $uniq{$_} = 1 foreach @holdArr; I prefer "foreach" to "for", mainly because it is shorter. Alternative: @[EMAIL PROTECTED] = (1) x @holdArr; Test-1: perl -MData::Dumper -wle' @keys = qw(a b c) ; @hash{ @keys } = (1) x @keys ; print Dumper \%hash ' $VAR1 = {

Re: Sort uniq

2006-10-18 Thread Rob Dixon
Shiping Wang wrote: At 02:04 PM 10/18/2006, Johnson, Reginald (GTI) wrote: I am trying to understand this sort and uniq code that a came across in the archive. This works, but I thought the %uniq would have the sort and uniqed values. What is needed if I didn't want to print the values out imme

Re: Sort uniq

2006-10-18 Thread Paul Johnson
On Wed, Oct 18, 2006 at 03:04:32PM -0400, Johnson, Reginald (GTI) wrote: > I am trying to understand this sort and uniq code that a came across in > the archive. I don't see anything to do with sort in this code. > This works, but I thought the %uniq would have the sort > and uniqe

Re: Sort uniq

2006-10-18 Thread Shiping Wang
At 02:04 PM 10/18/2006, Johnson, Reginald (GTI) wrote: I am trying to understand this sort and uniq code that a came across in the archive. This works, but I thought the %uniq would have the sort and uniqed values. What is needed if I didn't want to print the values out immediatedly but put them

Re: sort {} to work with undef values when its expecting an object

2006-04-26 Thread JupiterHost.Net
Tom Phoenix wrote: On 4/25/06, JupiterHost.Net <[EMAIL PROTECTED]> wrote: sort { $a->value() cmp $b->value() || $a->part('Name')->value() cmp $b->part('Name')->value() } grep { defined } @objects But sometimes $a->part('Name') returns undef, so the sort

Re: sort {} to work with undef values when its expecting an object

2006-04-25 Thread Tom Phoenix
On 4/25/06, JupiterHost.Net <[EMAIL PROTECTED]> wrote: > sort { > $a->value() cmp $b->value() > || > $a->part('Name')->value() cmp $b->part('Name')->value() > } > grep { defined } @objects But sometimes $a->part('Name') returns undef, so the sort fails.

Re: sort {} to work with undef values when its expecting an object

2006-04-25 Thread JupiterHost.Net
Jay Savage wrote: On 4/25/06, JupiterHost.Net <[EMAIL PROTECTED]> wrote: for my $obj( sort { $a->value() cmp $b->value() || $a->part('Name')->value() cmp $b->part('Name')->value() } grep { defined } @objects ) { ... $a/$b->value() always works since if $

Re: sort {} to work with undef values when its expecting an object

2006-04-25 Thread JupiterHost.Net
Timothy Johnson wrote: Just a thought, but couldn't you put the logic in your grep statement? Something like this: grep {defined($_->value()) or defined($_->part('Name')->value())} @objects; The only problem is then that the object woudl be completely skipped. I need all objects regardles

RE: sort {} to work with undef values when its expecting an object

2006-04-25 Thread Timothy Johnson
Just a thought, but couldn't you put the logic in your grep statement? Something like this: grep {defined($_->value()) or defined($_->part('Name')->value())} @objects; -Original Message- From: JupiterHost.Net [mailto:[EMAIL PROTECTED] Sent: Tuesday, April 25, 2006 12:22 PM To: beginne

Re: sort {} to work with undef values when its expecting an object

2006-04-25 Thread Jay Savage
On 4/25/06, JupiterHost.Net <[EMAIL PROTECTED]> wrote: > for my $obj( > sort { > $a->value() cmp $b->value() > || > $a->part('Name')->value() cmp $b->part('Name')->value() > } > grep { defined } @objects > ) { > > ... > > $a/$b->value() always works since i

Re: sort files by creation time

2005-12-15 Thread Bob Showalter
Randal L. Schwartz wrote: "Jeff" == Jeff Pang <[EMAIL PROTECTED]> writes: Jeff> and we can use the _ handle to avoid stat'ing twice. Jeff> Sorry,I don't know what is _ handle.Who help explain with it please,thanks. It's documented. I refuse to retype the docs for a thing. :) Specifically

Re: sort files by creation time

2005-12-14 Thread Randal L. Schwartz
> "Jeff" == Jeff Pang <[EMAIL PROTECTED]> writes: Jeff> and we can use the _ handle to avoid stat'ing twice. Jeff> Sorry,I don't know what is _ handle.Who help explain with it please,thanks. It's documented. I refuse to retype the docs for a thing. :) -- Randal L. Schwartz - Stonehenge Co

Re: sort files by creation time

2005-12-14 Thread Jeff Pang
and we can use the _ handle to avoid stat'ing twice. Sorry,I don't know what is _ handle.Who help explain with it please,thanks. -Original Message- From: "Randal L. Schwartz" Sent: Dec 14, 2005 11:56 PM To: beginners@perl.org Subject: Re: sort files by creati

Re: sort files by creation time

2005-12-14 Thread Randal L. Schwartz
> "Todd" == Todd W <[EMAIL PROTECTED]> writes: Todd> my @files = map $_->[0], Todd> sort { $b->[1] <=> $a->[1] } Todd> map [ $_, -M ], Todd> grep -f, # get only plain files Todd> glob("/mnt/qdls/MSDSIN/*"); Since the map can also serve as a grep, and we can

Re: sort files by creation time

2005-12-13 Thread JupiterHost.Net
OXx wrote: Hello all, I try to launch my perl application as a windows service. I compile it with PAR so I have mysoft.exe Then i installed win32::daemon, no problem. I try this script so: use Win32::Daemon; a) always always always: use strict; use warnings; on code you post to this lis

Re: sort files by creation time

2005-12-13 Thread OXx
Hello all, I try to launch my perl application as a windows service. I compile it with PAR so I have mysoft.exe Then i installed win32::daemon, no problem. I try this script so: use Win32::Daemon; %Hash = ( machine => '', name=> 'PerlTest', display => 'Oh m

RE: sort files by creation time

2005-12-13 Thread Brian Volk
-Original Message- From: Brian Volk Sent: Tuesday, December 13, 2005 8:10 AM To: 'Brian Franco' Subject: RE: sort files by creation time -Original Message- From: Brian Franco [mailto:[EMAIL PROTECTED] Sent: Monday, December 12, 2005 7:34 PM To: Brian Volk Subject

Re: sort files by creation time

2005-12-13 Thread Bob Showalter
Brian Volk wrote: Of course I have one more rookie question and a reference to a perldoc is just fine. :~) If I use the following code, why do I not need to declare the $a and the $b w/ my? Correct. This is explained in perldoc perlvar: $a $b Special package variables when using sor

Re: sort files by creation time

2005-12-12 Thread Brian Volk
Todd W wrote: "Brian Volk" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] After running a few tests... :~) I think I might be able to sort on the inode... ? Does this make sense? my @files = glob("/mnt/qdls/MSDSIN/*"); foreach my $file (@files) { print "$file\n"; my $in

RE: sort files by creation time

2005-12-12 Thread Brian Volk
-Original Message- From: Bob Showalter [mailto:[EMAIL PROTECTED] Sent: Monday, December 12, 2005 4:44 PM To: Brian Volk Cc: 'beginners@perl.org' Subject: Re: sort files by creation time Brian Volk wrote: > Hi All~ > > > > I'm using the glob function to

RE: sort files by creation time

2005-12-12 Thread Wagner, David --- Senior Programmer Analyst --- WGO
Brian Volk wrote: > Hi All~ > > > > I'm using the glob function to grab all the files in a given > directory and then using crontab to check it every 5 minutes. Once I > have the files I'm using the diamond operator to read every line in > every file and *do something* if the line matches. He

Re: sort files by creation time

2005-12-12 Thread Todd W
"Brian Volk" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > After running a few tests... :~) I think I might be able to sort on the > inode... ? Does this make sense? > > my @files = glob("/mnt/qdls/MSDSIN/*"); > > foreach my $file (@files) { > >print "$file\n"; >my $ino =

RE: sort files by creation time

2005-12-12 Thread Ryan Frantz
> -Original Message- > From: Brian Volk [mailto:[EMAIL PROTECTED] > Sent: Monday, December 12, 2005 4:47 PM > To: beginners@perl.org > Subject: RE: sort files by creation time > > After running a few tests... :~) I think I might be able to sort on the > inode...

RE: sort files by creation time

2005-12-12 Thread Timothy Johnson
You could try something along these lines, where I create an array prepending the date in Perl time format and then sort the array. There is probably a better way, but this would work. Note: (stat $file)[9] is a list slice that represents only the 9th element of the list returned by 'stat $file

RE: sort files by creation time

2005-12-12 Thread Brian Volk
After running a few tests... :~) I think I might be able to sort on the inode... ? Does this make sense? my @files = glob("/mnt/qdls/MSDSIN/*"); foreach my $file (@files) {

Re: sort files by creation time

2005-12-12 Thread Bob Showalter
Brian Volk wrote: Hi All~ I'm using the glob function to grab all the files in a given directory and then using crontab to check it every 5 minutes. Once I have the files I'm using the diamond operator to read every line in every file and *do something* if the line matches. Here's my ques

Re: sort with special order

2005-10-03 Thread Jeff 'japhy' Pinyan
[sorry, PINE has become very confused about who said what] On Oct 3, Jay Savage said: On 10/3/05, Bakken, Luke <[EMAIL PROTECTED]> wrote: JupiterHost.Net wrote: >> On Oct 3, JupiterHost.Net said: >> >>> I have a list of strings that start with an uppercase B, Q, or Z >>> >>> I need to sort them

Re: sort with special order

2005-10-03 Thread John W. Krahn
Bakken, Luke wrote: > JupiterHost.Net wrote: >>>On Oct 3, JupiterHost.Net said: >>> I have a list of strings that start with an uppercase B, Q, or Z I need to sort them so they are in order of Q, B , then Z Any ideas or input on how to efficiently do that with sort() or even >

Re: sort with special order

2005-10-03 Thread Jay Savage
On 10/3/05, Bakken, Luke <[EMAIL PROTECTED]> wrote: > JupiterHost.Net wrote: > >> On Oct 3, JupiterHost.Net said: > >> > >>> I have a list of strings that start with an uppercase B, Q, or Z > >>> > >>> I need to sort them so they are in order of Q, B , then Z > >>> > >>> Any ideas or input on how t

RE: sort with special order

2005-10-03 Thread Bakken, Luke
JupiterHost.Net wrote: >> On Oct 3, JupiterHost.Net said: >> >>> I have a list of strings that start with an uppercase B, Q, or Z >>> >>> I need to sort them so they are in order of Q, B , then Z >>> >>> Any ideas or input on how to efficiently do that with sort() or even >>> map() is most appre

Re: [SPAM DETECT] Re: sort with special order

2005-10-03 Thread Jeff 'japhy' Pinyan
On Oct 3, Xavier Noria said: On Oct 3, 2005, at 18:16, Jeff 'japhy' Pinyan wrote: my @sorted = map { tr/123/QBZ/; $_ } sort map { tr/QBZ/123/; $_ } @data; There's a potential gotcha there: since all Qs and Bs are being swapped lexicographic order after the first character

Re: sort with special order

2005-10-03 Thread JupiterHost.Net
On Oct 3, JupiterHost.Net said: I have a list of strings that start with an uppercase B, Q, or Z I need to sort them so they are in order of Q, B , then Z Any ideas or input on how to efficiently do that with sort() or even map() is most appreciated :) perldoc -f sort|-f map didn't appear to

Re: [SPAM DETECT] Re: sort with special order

2005-10-03 Thread Xavier Noria
On Oct 3, 2005, at 18:16, Jeff 'japhy' Pinyan wrote: On Oct 3, JupiterHost.Net said: I have a list of strings that start with an uppercase B, Q, or Z I need to sort them so they are in order of Q, B , then Z Any ideas or input on how to efficiently do that with sort() or even map() is mos

Re: sort with special order

2005-10-03 Thread Jeff 'japhy' Pinyan
On Oct 3, JupiterHost.Net said: I have a list of strings that start with an uppercase B, Q, or Z I need to sort them so they are in order of Q, B , then Z Any ideas or input on how to efficiently do that with sort() or even map() is most appreciated :) perldoc -f sort|-f map didn't appear to

Re: sort with special order

2005-10-03 Thread Xavier Noria
On Oct 3, 2005, at 17:35, JupiterHost.Net wrote: I need to sort them so they are in order of Q, B , then Z The real array will have between 1 to 100 items, just FYI They all go in ASCII relative order except B <-> Q, thus a way to get it is to handle that special case and delegate to cmp

  1   2   3   >