Date: Tue, 25 Apr 2006 19:54:27 -0500 From: "Nikolas Britton" <nikolas.britton@gmail.com> To: "FreeBSD Questions" <questions@freebsd.org> Subject: Re: Perl: sort string alphabetically, or remove dupe chars? Message-ID: <ef10de9a0604251754r3292719dqc29d96095a9f0752@mail.gmail.com> In-Reply-To: <ef10de9a0604251540p6461bfedgf788d500a81e7190@mail.gmail.com> References: <ef10de9a0604251540p6461bfedgf788d500a81e7190@mail.gmail.com>
index | next in thread | previous in thread | raw e-mail
On 4/25/06, Nikolas Britton <nikolas.britton@gmail.com> wrote:
> basically what I want to do:
>
> my @wordlist = (letter, remember, alphabetically);
> ## some whizbang code that changes words like
> ## "letter" to "eelrtt", remember to beeemmrr,
> ## and alphabetically to aaabcehilllpty.
> @foobar =~ tr///cs; #hmm, doesn't work.
> print "@wordlist\n";
>
> Hmm, that's broke, how about this:
>
> my $wordlist = "letter";
> ## some whizbang regex that removes dupe chars
> ## from words like "alphabetically" --> "alphbeticy".
> print "$wordlist\n";
>
This works... but it's clunky:
my $string = "letter";
my @chars = split("", $string);
$string = ""; @chars = sort (@chars);
foreach (@chars) {
$string .= $_;
}
$string =~ tr///cs;
print "$string";
--
BSD Podcasts @ http://bsdtalk.blogspot.com/
help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?ef10de9a0604251754r3292719dqc29d96095a9f0752>
