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