There are a few items in this script worth noting. Next, we sort the array using the sort defined in the subroutine byName . Lastly, we list out the results using foreach . A flat file to be used for this kind of comparison must be sorted on the data in several logical columns instead of just one. Perl's join function can be used to combine our substrings in the appropriate order for our sort.
Comments identify the logical columns that are being used to construct the sort strings.
The rest of the script using this sort subroutine is identical to that in the previous example. In this case, alphanumeric sorting order is preserved by keeping join from inserting anything between the columns. A different approach is needed in order to sort a tab-delimited flat file. Our reference book reveals a useful function, split , which can change a line of text into an array of strings, dividing the line based on a key character or string. This sort also has several exit-points instead of one.