The stupid question is the question not asked | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
There are two built in sorting operators in Perl - <=> and cmp - which are discussed in Equality Operators. <=> is used for numerical comparison and cmp is used for string comparison. Since the data from your first column are string data, you should use cmp.
If neither operator fits your requirements, you can design your own comparison function, following the instructions in sort. On a side note, why are you using Text::CSV_XS if you are not using any of the code? Why are you both requiring and using the module when these are redundant operations? Why are you manually stripping leading zeros and why are you still feeding the numeric comparison operator values with leading quotes, even after I pointed out (Re^2: How do I sort a CSV file on multiple columns?) that it doesn't work the way you expect? Why are you posting code that has use strict commented out? See How do I post a question effectively?. Update: I also just noticed that your @rows array contains strings, not array refs like your sort function expects. The line $result = join (",", @fields); concatenates all of the values in the array @fields into a single, comma-separated string. You then attempt to access each of those strings as if they were array refs, an issue that would have been caught by use strict;. To understand how to use references in Perl, read perlref, perlreftut and/or perllol. Compare your code to the code I've already referenced above to see a prototype of how you should be accessing these data structures. In reply to Re: Sorting help
by kennethk
|
|