in reply to sorting with substrings
If you're not familiar with map and sort, essentially, they act like "pipes" or "filters" that pass list data from the right side to the left, while giving you the option to perform some operation on each element of the list before you pass it on. So, it might help to start on the last line of the above example and follow the @data as it flows upwards into @sorted.my @data = qw( workstation_1_1 workstation_1_2 voiceserver_1_2 voiceserver_1_1 ); my @sorted = map { join('_', @{$_} ) # put the data back together again } sort { $a->[2] <=> $b->[2] # first sort by the final digit || $b->[0] cmp $a->[0] # then by the name, descending } map { # seperate the data out into seperate "fields" for easy # sorting (typically called a "Schwartzian Transform") [ split(/_/,$_) ] } @data; # the operation starts here (believe it or not)
|
---|