Re: Perl: sort string alphabetically, or remove dupe chars?
On Apr 26, 2006, at 12:34 AM, Nikolas Britton wrote: On 4/25/06, Parv [EMAIL PROTECTED] 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. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Perl: sort string alphabetically, or remove dupe chars?
On 4/27/06, Andrew Reitz [EMAIL PROTECTED] wrote: On Apr 26, 2006, at 12:34 AM, Nikolas Britton wrote: On 4/25/06, Parv [EMAIL PROTECTED] 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. 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 = qr{^$sedstring1$}; my %freq;#keys = characters, values = frequency count while (DATA) { chomp; if (/$regex/) { push @guesswords, \n$_; $_ =~ s/[$solvedletters1]//g; my @chars = split(, $_); $_ = ; @chars = sort (@chars); foreach (@chars) { $foobar3 .= $_; } $_ = $foobar3; $foobar3 = ; $_ =~ tr///cs; #print $_\n; # For debugging $freq{$_}++ for split(//, lc $_); } } $_ = scalar @guesswords; print Guesswords in list: $_\n; if (@guesswords = 20) { print @guesswords\n\n; } # Print probabilities list. foreach $_ (sort {$freq{$a} = $freq{$b}} (keys(%freq))) { print $_\t=\t$freq{$_}\n; } -- BSD Podcasts @ http://bsdtalk.blogspot.com/ ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Perl: sort string alphabetically, or remove dupe chars?
On 4/25/06, Parv [EMAIL PROTECTED] wrote: in message [EMAIL PROTECTED], wrote Nikolas Britton thusly... This works... but it's clunky: my $string = letter; my @chars = split(, $string); $string = ; @chars = sort (@chars); foreach (@chars) { $string .= $_; } $string =~ tr///cs; print $string; You could combine some of the steps ... my $string = 'letter'; $string = join '' , sort split '', $string; $string =~ tr///cs; print $string; ... another but rather clunky version is ... my $string = 'letter'; { my %string; @string{ split '' , $string } = (); $string = 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 = `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; } 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.cfm -- BSD Podcasts @ http://bsdtalk.blogspot.com/ ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Perl: sort string alphabetically, or remove dupe chars?
On 4/25/06, Nikolas Britton [EMAIL PROTECTED] wrote: basically what I want to do: my @wordlist = (letter, remember, alphabetically); ## some whizbang code that changes words like ## letter to eelrtt, remember to beeemmrr, ## and alphabetically to aaabcehilllpty. @foobar =~ tr///cs; #hmm, doesn't work. print @wordlist\n; Hmm, that's broke, how about this: my $wordlist = letter; ## some whizbang regex that removes dupe chars ## from words like alphabetically -- alphbeticy. print $wordlist\n; This works... but it's clunky: my $string = letter; my @chars = split(, $string); $string = ; @chars = sort (@chars); foreach (@chars) { $string .= $_; } $string =~ tr///cs; print $string; -- BSD Podcasts @ http://bsdtalk.blogspot.com/ ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Perl: sort string alphabetically, or remove dupe chars?
in message [EMAIL PROTECTED], wrote Nikolas Britton thusly... On 4/25/06, Nikolas Britton [EMAIL PROTECTED] wrote: basically what I want to do: ... my $wordlist = letter; ## some whizbang regex that removes dupe chars ## from words like alphabetically -- alphbeticy. print $wordlist\n; ... This works... but it's clunky: my $string = letter; my @chars = split(, $string); $string = ; @chars = sort (@chars); foreach (@chars) { $string .= $_; } $string =~ tr///cs; print $string; You could combine some of the steps ... my $string = 'letter'; $string = join '' , sort split '', $string; $string =~ tr///cs; print $string; ... another but rather clunky version is ... my $string = 'letter'; { my %string; @string{ split '' , $string } = (); $string = join '' , sort keys %string; } print $string; - Parv -- ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]