i need a syntax to sort elements of an array to remove duplicacy if any.
i tried sort -u to sort a file BUT i need to do this sorting on array.
plz help me if it could be.
with regard
hi,
have you tried using the function sort
sort will sort the given array and return an sorted array.
suppose you have got an array named array1 with duplicate data in unsorted manner.
@array2 = sort(@array1);
open(fp1,">file.txt") || die "could not open the file for writting";
foreach my $element (@array1)
{
print fp1 $element;
print fp1 "\n";
}
close(fp1);
#fire the uniq command on the file and redirect the output to a new file
system("uniq file.txt > file1.txt");
#dump the vontnet of file in array;
open(fp2,"file1.txt");
@array3=<fp2>;
close(fp3);
#array3 contains the uniw sorted data
#you can even use other logic to picj uniq elements from the array.
let me know if this approch solves your problem.