From owner-freebsd-questions@FreeBSD.ORG Wed Apr 26 07:41:27 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 40FC216A403 for ; Wed, 26 Apr 2006 07:41:27 +0000 (UTC) (envelope-from nikolas.britton@gmail.com) Received: from uproxy.gmail.com (uproxy.gmail.com [66.249.92.170]) by mx1.FreeBSD.org (Postfix) with ESMTP id 48CB343D58 for ; Wed, 26 Apr 2006 07:41:26 +0000 (GMT) (envelope-from nikolas.britton@gmail.com) Received: by uproxy.gmail.com with SMTP id m3so1119809ugc for ; Wed, 26 Apr 2006 00:41:25 -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=AhxmtMFfod52E/Jfre0CY3WQiUTWHO2HNQN7L+Szjy92zPOwbIido5hbv3IopQEqK8ebk9hlqg5WnMBVgSYQR+lDdvaqXIa9DK9wK277rl6lm/4fWXLxnOHPsF9dX4svhoZoO94m+vbSxr7bZKMO+VVYyrW7ln2fEQmkqIzaFIQ= Received: by 10.78.39.16 with SMTP id m16mr315734hum; Wed, 26 Apr 2006 00:34:57 -0700 (PDT) Received: by 10.78.15.10 with HTTP; Wed, 26 Apr 2006 00:34:57 -0700 (PDT) Message-ID: Date: Wed, 26 Apr 2006 02:34:57 -0500 From: "Nikolas Britton" To: "Nikolas Britton" , "FreeBSD Questions" In-Reply-To: <20060426030535.GA1540@holestein.holy.cow> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <20060426030535.GA1540@holestein.holy.cow> 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 07:41:27 -0000 On 4/25/06, Parv wrote: > in message , > wrote Nikolas Britton thusly... > > > > 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"; > > You could combine some of the steps ... > > my $string =3D 'letter'; > $string =3D join '' , sort split '', $string; > $string =3D~ tr///cs; > print $string; > > ... another but rather clunky version is ... > > my $string =3D 'letter'; > { > my %string; > @string{ split '' , $string } =3D (); > $string =3D join '' , sort keys %string; > } > print $string; > Thanks parv... I meant the algorithm was clunky, not the code... I'm so new at this that I can't read your code, and I have a hard enough time reading mine own :-). I've got another simple problem now. How do I get this code to stop printing everything on a newline, I'm not using \n in my print statement so why does it do that and how do I get it to stop? @wordlist1 =3D `sed /^$sedstring1\\\$/\\!d < enable2k_wordlist`; foreach (@wordlist1) { $string =3D $_; $string =3D~ s/[$solvedletters1]//g; my @chars =3D split("", $string); $string =3D ""; @chars =3D sort (@chars); foreach (@chars) { $string .=3D $_; } $string =3D~ tr///cs; print "$string"; } Then I have to make a probabilty engine to count the frequency of the letters I get from the above code block. looking for something simple like this: http://www.amstat.org/publications/jse/secure/v7n2/count-char.cf= m -- BSD Podcasts @ http://bsdtalk.blogspot.com/