Feel free to copy, modify and share what you like.
Sort words in string with Perl
This example shows how to sort words in a string:
my $str = 'bc ab cd ac';
print $str.$/;
$str = sortString($str);
print $str.$/;
sub sortString {
return join " ",sort {$a gt $b} split / /,$_[0];
}
And as result we get this:
bc ab cd ac
ab bc ac cd
One thought on “Sort words in string with Perl”
When someone writes an article he/she retains the idea of a
user in his/her brain that how a user can know it.
Therefore that’s why this piece of writing is perfect. Thanks!
When someone writes an article he/she retains the idea of a
user in his/her brain that how a user can know it.
Therefore that’s why this piece of writing is perfect. Thanks!