#!/usr/bin/perl -w use strict; my ($miss, $guesses, $guess, @build, $tries, @guessed, @wordbank); @wordbank=qw(cubicle scramble deduction envelope century rediculous); +#as many words as you like. my $selected=rand(scalar(@wordbank)); my (@word)=split(//, $wordbank[$selected]); @build=("_") x scalar(@word); $_=join('',@word); $miss=0; $guesses="0-<--<"; $tries=0; print "Welcome to HangPerl Hangman ver 0.56... mentained by: Nimster\n +"; print "Word has "; print scalar(@word); print " letters\n"; print "Your hangman: "; print $guesses; print "\n"; print "Good luck! Start guessin`!\n"; while (1) { last if $miss==length($guesses); last if join('',@build) eq join('',@word); $guess=<STDIN>; chomp $guess; $guess=lc(substr($guess,0,1)); $tries+=1; if (m/$guess/) { print "right!\n"; for(my $index=0; $index<scalar(@word); $index++) { $build[$index]=$word[$index] if ($word[$index] eq $guess); } foreach my $letter (@build) { print "$letter "; } print "\n"; } else { $miss++; print substr($guesses, $miss, length($guesses)); print "\n"; } } print "It took you $tries tries ($miss misses) and "; if ($miss < length($guesses)) { print "You made it!\n"; } else { print "You failed.\n"; } #it can be made much more effective easily (elimination of @word/$curr +word which are basically the same, same with some more variables, so +changes in the algorythm, etc. However, this is my first try at a rea +l, kinda full perl program. Soon to be ported to CGI, then maybe I'll + add DBM highscores, etc.

In reply to Perl Hangman by Nimster

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.