Why the big suprise. unless is just syntactic sugar for if not. In the traditional manner, you should read if statements as

if condition is true do clause

so you should read unless statements as

if condition is not true do clause

(of course perl lets you write those as do ... if too)

So in your example you're saying if 1 is not true, print hello. Since 1, by definition, is true, you'll always print "WHAT?!!!\n".

-derby

update Damn ... just re-read the OP and realized the big suprise wasn't that it didn't print "Hello" but that you could place an "else" block after "unless." The syntactic sugar part still holds (its just an if (! condition)) but sorry about the rest.


In reply to Re: unless....else by derby
in thread unless....else by amrangaye

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.