I have a set of strings:
20120160323001.z1.xml
20120160324001.z1.xml
20120160322001.z1.xml# The file format is XXXYYYYMMDDVVV.z1.xml where XXX is a
# medical code, YYYYMMDD is a date and VVV is a document
# version number
I want to sort the strings according to the date in descending order. So, the above strings after sorting will be:
20120160324001.z1.xml
20120160323001.z1.xml
20120160322001.z1.xml
I know how to sort arrays in Perl but given the complex file name I'm confused how I can sort these strings by date? Is it possible?
# The below sort function is not going to work for these filenames
sub rev_by_date {
$b->[9+1] <=> $a->[9+1]
}
my @sorted_files = sort rev_by_date @files;
Edit I use this regular expression to find these files: (?^:^201.*.z1.xml) but its not that useful for the date sorting function. In the date sorting function I dont know if comparing date strings will even work?
(?^:...)which is primarily for writing a pattern that will be embedded within another. It resets all options to the defaults for the contents of the parentheses. You are also using dots—which will match any character—to match literal dots in the target string. Please don't copy code from the internet without understanding what it does.