Date: Wed, 26 Apr 2006 02:34:57 -0500 From: "Nikolas Britton" <nikolas.britton@gmail.com> To: "Nikolas Britton" <nikolas.britton@gmail.com>, "FreeBSD Questions" <questions@freebsd.org> Subject: Re: Perl: sort string alphabetically, or remove dupe chars? Message-ID: <ef10de9a0604260034y7c27ca88l417f8fc0f495859a@mail.gmail.com> In-Reply-To: <20060426030535.GA1540@holestein.holy.cow> References: <ef10de9a0604251540p6461bfedgf788d500a81e7190@mail.gmail.com> <ef10de9a0604251754r3292719dqc29d96095a9f0752@mail.gmail.com> <20060426030535.GA1540@holestein.holy.cow>
next in thread | previous in thread | raw e-mail | index | archive | help
On 4/25/06, Parv <parv@pair.com> wrote: > in message <ef10de9a0604251754r3292719dqc29d96095a9f0752@mail.gmail.com>, > 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/
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?ef10de9a0604260034y7c27ca88l417f8fc0f495859a>