Here's how I rewrote your code, with some explanations. This is like to make your code look more perlish, though this is how *I* 'd see your code (with heavy comments).
Should I code it myself, it would be different again...

#!c:\perl\bin\perl.exe -w # -w means "warn me if I do anything that i may not want to do (ie: ma +ke a typo in a var name)" use strict; #Because God wants it my $guess; #declare it somewhere like here seems nice TOP: my $tries = 10; my $value = int(rand(200)); print "Pick a number between 0 and 200.\nYou have ",$tries--," guesses + left.\n"; #Do it in one line. #the $tries-- prints $tries and then, decrements it. while ($tries>0 and defined ($guess=<STDIN>)){ #since you reread $guess each time, why not write it just once? #then until became a while, so I inversed the $tries test too. #defined is used because the <STDIN> can be undefined... #put the $tries test first, so that it doesn't ask for input when yo +u're over next if $guess!~m/^\d+\n$/; #this might be a bit ugly right now #just learn this as "it is an integer followed by a carriage return" + #And then, read about regexps if($guess>$value){ print "You need to guess a lower number.\nGuesses left: ",$tries-- +,"\n"; next; # jump again to the while loop NOW #same hacks as above. } if($guess<$value){ print "You need to guess a higher number.\nGuesses left: ",$tries- +-,"\n"; next; #same hacks as above. } #beeing here means we didn't jumped before (the "next"'s were not ca +lled print "You guessed my number in ",(10-$tries)," guesses. Thanks for +playing.\n"; $tries=0; } print "Sorry, you ran out of guesses. My number was $value\n" if ($gu +ess != $value); #Since the test is a "simple" if (this) then {just that} #you can write just that if (this); #looks like English. Easy to read. print "Play Again? (y/n) \n"; chomp(my $again = <STDIN>); #chomp ($again); goto TOP if($again =~m/y/i);#I don't like goto, but that's your code. #=~ means check this var #m/foo/ means "does it contain the word foo" #i means case insensitive #once again, the if can be written easier #else not needed! print "Goodbye!";

Once again, this is how *I* would see *your* code
Read some nodes, read some tuts and docs, learn the idioms, and then you'll write your perlish perl code.

P!

In reply to Re: Number Guess by Pied
in thread Number Guess by cryptoquip

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.