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

Sorting an array by a substring of its members

2008-12-15 Thread Christopher Yee Mon
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, $b) = @_; $a =~ s/^(.*?),