From owner-freebsd-questions@FreeBSD.ORG Wed Apr 26 00:54:30 2006 Return-Path: X-Original-To: questions@freebsd.org Delivered-To: freebsd-questions@FreeBSD.ORG Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 0886816A403 for ; Wed, 26 Apr 2006 00:54:30 +0000 (UTC) (envelope-from nikolas.britton@gmail.com) Received: from uproxy.gmail.com (uproxy.gmail.com [66.249.92.175]) by mx1.FreeBSD.org (Postfix) with ESMTP id 67F2B43D45 for ; Wed, 26 Apr 2006 00:54:29 +0000 (GMT) (envelope-from nikolas.britton@gmail.com) Received: by uproxy.gmail.com with SMTP id m3so1077508ugc for ; Tue, 25 Apr 2006 17:54:28 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=XlGEwytAU4mARkk80ft64iFIA0kJskZT+Zln6zBphtQb3nrBYIS5jFw4u6v+aJCsSE61EAivzC/WNjxhjFiWyxFWHHT89s9re/9OPU1NeE9P2R0X+Pkw0qsG22+NwSn0R5M5ue4RW7+esSzqNNf9O8wGJHI8bpfupR7XXSBl5IU= Received: by 10.78.57.11 with SMTP id f11mr302844hua; Tue, 25 Apr 2006 17:54:27 -0700 (PDT) Received: by 10.78.15.10 with HTTP; Tue, 25 Apr 2006 17:54:27 -0700 (PDT) Message-ID: Date: Tue, 25 Apr 2006 19:54:27 -0500 From: "Nikolas Britton" To: "FreeBSD Questions" In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: Cc: Subject: Re: Perl: sort string alphabetically, or remove dupe chars? X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 26 Apr 2006 00:54:30 -0000 On 4/25/06, Nikolas Britton 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/