From owner-freebsd-questions@FreeBSD.ORG Thu Apr 27 20:10:38 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 324F916A402 for ; Thu, 27 Apr 2006 20:10:38 +0000 (UTC) (envelope-from nikolas.britton@gmail.com) Received: from uproxy.gmail.com (uproxy.gmail.com [66.249.92.174]) by mx1.FreeBSD.org (Postfix) with ESMTP id E7EC843D48 for ; Thu, 27 Apr 2006 20:10:36 +0000 (GMT) (envelope-from nikolas.britton@gmail.com) Received: by uproxy.gmail.com with SMTP id m3so1420736ugc for ; Thu, 27 Apr 2006 13:10:35 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=i023UR/9wBsV0k4kQx7NvnD5YUMG5qnZhF4SPVMte4vDa10qRrBUuHknVKnn1OuZOVErlngp1NMxa5z5+W9pc9rLk0Z4ps1c2B9FYAnY0Q+NjhK0soUZj9p6hHooqPRzxfV0HX0+nYNrrIc6DtVqsZh4ZhKTWBxs/VcUeiGTiAQ= Received: by 10.78.58.11 with SMTP id g11mr294416hua; Thu, 27 Apr 2006 13:10:35 -0700 (PDT) Received: by 10.78.15.10 with HTTP; Thu, 27 Apr 2006 13:10:35 -0700 (PDT) Message-ID: Date: Thu, 27 Apr 2006 15:10:35 -0500 From: "Nikolas Britton" To: "Andrew Reitz" In-Reply-To: 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: FreeBSD Questions 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: Thu, 27 Apr 2006 20:10:38 -0000 On 4/27/06, Andrew Reitz wrote: > > On Apr 26, 2006, at 12:34 AM, Nikolas Britton wrote: > > > On 4/25/06, Parv wrote: > [snip] > > 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"; > > } > > Hi Nikolas, > > Most likely, your input has '\n' characters at the end of every line, > and you aren't doing anything in perl to strip those away. Try adding > a 'chomp($string);' line before you print. > Hey thanks, I think I did try that already... anyways... it doesn't matter now because I reworked the code block, this is what I have so far: open(DATA, "< $wordlistfile") or die "Couldn't open $wordlistfile for reading: $!\n"; $regex =3D qr{^$sedstring1$}; my %freq; #keys =3D characters, values =3D frequency count while () { chomp; if (/$regex/) { push @guesswords, "\n$_"; $_ =3D~ s/[$solvedletters1]//g; my @chars =3D split("", $_); $_ =3D ""; @chars =3D sort (@chars); foreach (@chars) { $foobar3 .=3D $_; } $_ =3D "$foobar3"; $foobar3 =3D ""; $_ =3D~ tr///cs; #print "$_\n"; # For debugging $freq{$_}++ for split(//, lc $_); } } $_ =3D scalar @guesswords; print " Guesswords in list: $_\n"; if (@guesswords <=3D "20") { print "@guesswords\n\n"; } # Print probabilities list. foreach $_ (sort {$freq{$a} <=3D> $freq{$b}} (keys(%freq))) { print " $_\t=3D>\t$freq{$_}\n"; } -- BSD Podcasts @ http://bsdtalk.blogspot.com/