I think now I am understanding the script. However, I ended up commenting out the @guesses portion (mainly because I think @guesses is useless part and script still works)..
Was author wrong to put that code there(since it does nothing?).
#!/usr/bin/perl -w @words = qw( hi no ); @guesses=(); $wrong=0; $choice=$words[rand @words]; $hangman="0-|--<"; @letters=split(//, $choice); print "\@letters is @letters\n"; @hangman=split(//, $hangman); @blankword=(0) x scalar(@letters); print "\@blankword is @blankword\n"; OUTER: while ($wrong<@hangman) { print "whielloop\n"; foreach $i (0..$#letters) { if ($blankword[$i]) { print $blankword[$i]; } else { print "-"; } } print "\n"; if ($wrong) { print @hangman[0..$wrong-1] } print "\n\n\n\n Your Guess: "; $guess=<STDIN>; chomp $guess; # foreach(@guesses) { # print "foreach loop\n"; # print "\$guess is $guess\n"; # print "\$\_ is $_\n"; # next OUTER if ($_ eq $guess); # } # print "\@guesses is @guesses\n"; # $guess_scalar = "@guesses"; # print "\$guess_scalar is $guess_scalar\n"; #$guesses[@guesses]=$guess; # push @guesses, $guess; $right=0; for ($i=0; $i<@letters; $i++) { print "\$i is $i\n"; print "in the forloop\n"; if ($letters[$i] eq $guess) { $blankword[$i]=$guess; print "\$blankword\[\$i\] is $blankword[$i] +\n"; $right=1; } } $wrong++ if (not $right); print "\$wrong is $wrong\n"; if (join('', @blankword) eq $choice) { print "IF loop\n"; print "You got it right!\n"; exit;

In reply to Re^4: hangman question by convenientstore
in thread hangman question by convenientstore

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.