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>
next in thread | previous in thread | raw e-mail | index | archive | help
On 4/25/06, Nikolas Britton <nikolas.britton@gmail.com> wrote: > basically what I want to do: > > my @wordlist =3D (letter, remember, alphabetically); > ## some whizbang code that changes words like > ## "letter" to "eelrtt", remember to beeemmrr, > ## and alphabetically to aaabcehilllpty. > @foobar =3D~ tr///cs; #hmm, doesn't work. > print "@wordlist\n"; > > Hmm, that's broke, how about this: > > my $wordlist =3D "letter"; > ## some whizbang regex that removes dupe chars > ## from words like "alphabetically" --> "alphbeticy". > print "$wordlist\n"; > This works... but it's clunky: my $string =3D "letter"; my @chars =3D split("", $string); $string =3D ""; @chars =3D sort (@chars); foreach (@chars) { $string .=3D $_; } $string =3D~ tr///cs; print "$string"; -- BSD Podcasts @ http://bsdtalk.blogspot.com/
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?ef10de9a0604251754r3292719dqc29d96095a9f0752>