This is the first Perl program i've written with any substance. It's not too bad, but it's longer than I would've hoped it would be ~45 lines. Seems long, but it does the job.
while($input ne "end"){ print "Enter a word to find the isogram (end to exit): "; $input = ; chomp($input); $input = "\L$input"; if($input =~ /\W/) { print $input . " has an illegal character.\n"; } else { @allchars = split//,$input; @allchars = sort(@allchars); my %hash = (); for($i=0; $i<=$#allchars; $i++) { $hash{ @allchars[$i] }++; } $zVal = $hash{@allchars[0]}; $count = 0; while( ($key, $value) = each(%hash)) { if($value == $zVal){ $count++; } } if($count == (keys %hash)) { print "$input is a $hash{@allchars[0]} letter isogram.\n"; } else { print "$input is not an isogram.\n"; } }}
So, for example, if you enter TartAr (an example we were provided) the program will output that it is a 2 letter isogram since t, a, and r all occur twice. It's not bad, but the syntax after coming from C++ can be a bit weird. I'm sure there's a more efficient way to do it, but I don't know it [smile].
"An isogram (also known as a "nonpattern word") is a logological term for a word or phrase without a repeating letter."
Just a heads up ;-)