This blog post is about the sort function in Perl. Mostly it is from the book “perl for dummies”, since I am reading it now.
This is a good book, since it explains many concepts very clearly.
The “sort” function sorts a list alphabeticlly. Perl also allows us to sort a list according to the rule we defined.
if alphabetically, we can write the code as the following:
It will give the following result:
Here below I will show what we can do if we want to sort based on the way we want it to be:
The above code will sort the list according to the length of the string in the list.
What if the our so-called rule is a subroutine?
1 2 3 4 5
This post is going to be continued. I will add more things as I come accross more useful and interesing examples regarding the sort function.