Does anyone have a quick and dirty way of performing a sort and uniq in perl?
How an array with data like:
this is bkupArr[0] BOLADVICE_VN
this is bkupArr[1] MLT6800PROD2A
this is bkupArr[2] MLT6800PROD2A
this is bkupArr[3] BOLADVICE_VN_7YR
this is bkupArr[4] MLT6800PROD2A
I want to sort it and remove duplicates.
This would be simple using sort and uniq from the command line but I would like to accomplish it in perl if it is not to complicated.
That's not complicated, but of course that needs some code.
A hash in perl is good for filtering identical items by using hash keys. Then you can also use sort() to sort the items.
An example:
@array = ('Apple', 'Orange', 'Apple', 'Banana');
%hashTemp = map { $_ => 1 } @array;
@array_out = sort keys %hashTemp;
# @array_out contains ('Apple', 'Banana', 'Orange')
Cbkihong, thats exactly what I was looking for. Thanks.
ruby -e 'p %w(apple orange apple banana).uniq.sort'
Output:
["apple", "banana", "orange"]