Perl: sort string alphabetically, or remove dupe chars?
Andrew Reitz
ajr9 at po.cwru.edu
Thu Apr 27 07:37:34 UTC 2006
On Apr 26, 2006, at 12:34 AM, Nikolas Britton wrote:
> On 4/25/06, Parv <parv at pair.com> 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 = `sed /^$sedstring1\\\$/\\!d < enable2k_wordlist`;
> foreach (@wordlist1) {
> $string = $_;
> $string =~ s/[$solvedletters1]//g;
> my @chars = split("", $string);
> $string = ""; @chars = sort (@chars);
> foreach (@chars) {
> $string .= $_;
> }
> $string =~ 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.
-Andy Reitz.
More information about the freebsd-questions
mailing list