I read your code and it seems fine, not that I'd be able to discern between appallingly awful code and tremendously great code...

There are however a couple changes I'd make : first off, I'd use the pragma use strict; at the very beginning of your code - it then forces you to declare your variables the following way : my $a; or my $a = 17;...
It prevents you from mixing up eponymous variables specially when you go into loops.

Second of all, before even testing the number, I'd initialize ask for it... :
my $guess = 0; # can't be the right one then until($guess == $secret_number) { $guess = <STDIN>; # do the rest }
Hence the if (defined $guess is useless and you can directly write :
my $answer = ($guess>$secret_number?("bigger than"):($guess<$secret_number?("smaller than"):""))
I note that you've used eq : this is a string comparison tool. It's best you use == (as in C). On second thoughts, I've noticed you're using eq because of $guess = <STDIN> in which case you're right eq is better...

Lastly, instead of using $quit as a string which then makes you use regexes, you'd be better off using a byte : $quit = 1; or even a constant : $quit = YES provided you previouslt declared YES : use constant YES => 1...

Hope this helps...

In reply to Re: Bad Code? by Foggy Bottoms
in thread Bad Code? by Hayl_

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.