>-----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 line1
>2345 line2
>500 line3
>etc.
>
>Obviously \n is at end of every line in the string.  I need it sorted.
> How would I approach this?
>
   Since a \n is at end, then could use split like:
        for my $dtl ( sort {$a <=> $b} split(/\n/, $a_string) ) {
                # assuming numeric sort or if alpha, change <=> cmp
                # can do what you want with it at this point.
         }

         If you have any questions and/or problems, please let me know. 
         Thanks. 
 
Wags ;) 
David R. Wagner 
Senior Programmer Analyst 
FedEx Services 
1.719.484.2097 Tel 
1.719.484.2419 Fax 
1.408.623.5963 Cell
http://Fedex.com/us



>--
>To unsubscribe, e-mail: beginners-unsubscr...@perl.org
>For additional commands, e-mail: beginners-h...@perl.org
>http://learn.perl.org/
>


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to