It would be nice if the code your next post is self-consistent and reasonably indented. Did someone suggest that you get bonus points for using fewer lines and less white space? If so, whack that someone for giving you a bum steer... and make your next post readily readable. It'll help you get answers.

Also, consider your output: labeling make it easier to read and understand. Your tabs in the lines with which you disagreed was a big step in the right direction but consider how labeling makes the way you wrote your $var...s easier to know, from the output alone.

Something like this may serve as an example:

#!/usr/bin/perl use strict; use warnings; # 930247 my $var = 0; if ( $var ) { print "\$var ($var) True\n"; } else { print "\$var ($var) False\n"; } undef $var; if ( $var ) { print "\$var (undef) True\n"; } else { print "\$var (undef) False\n"; } my $var1 = ''; if ( $var1 ) { print "\$var1 ('') True\n"; } else { print "\$var1 ('') False\n"; } my $var2 = ""; if ( $var2 ) { print "\$var2 (\"\") True\n"; } else { print "\$var2 (\"\") False\n"; } my $var3 = '0'; if ( $var3 ) { print "\t \$var3 ($var3 - as a single-quoted number) True\n"; } else { print "\t \$var3 ($var3 - as a single-quoted number) False\n"; } my $var4 = "0"; if ( $var4 ) { print "\t \$var4 ($var4 - as a double-quoted number) True\n"; } else { print "\t \$var4\ ($var4 - as a double-quoted number) False\n"; } if ( $var4 == 0 ) { print "\t \$var4 ($var4 - as an unquoted number) True\n"; } else { print "\t \$var4 ($var4 - as an unquoted number) False\n"; } if ( $var4 eq '0' ) { print "\t \$var4 ($var4 - as a single-quoted number) True\n"; } else { print "\t \$var4 ($var4 - as a single-quoted number) False\n"; } print "\t \$var4 ($var4 - as a single-quoted number) has length of " +. length($var4) . " and ASCII value of " .ord($var4). "\n"; my $var5 = '1'; if ( $var5 ) { print "\$var5 ($var5 in single quotes) True\n"; } else { print "\$var5 ($var5 in single quotes) False\n"; } my $var6 = "1"; if ( $var6 ) { print "\$var6 ($var6 in double quotes) True\n"; } else { print "\$var6 ($var6 in double quotes) False\n"; } my $var7 = 1; if ( $var7 ) { print "\$var7 ($var7 - as an unquoted number) True\n"; } else { print "$var7 ($var7 - as an unquoted number) False\n"; }

and that produces this output:

$var (0) False $var (undef) False $var1 ('') False $var2 ("") False $var3 (0 - as a single-quoted number) False $var4 (0 - as a double-quoted number) False $var4 (0 - as an unquoted number) True $var4 (0 - as a single-quoted number) True $var4 (0 - as a single-quoted number) has length of 1 and AS +CII value of 48 $var5 (1 in single quotes) True $var6 (1 in double quotes) True $var7 (1 - as an unquoted number) True

You'll also note an (imperfect) effort to do the quoting for output in the same manner each time; that kind of consistency will also help make your code more understandable... and maintainable.

But most inportant -- make sure you grok davidos reply; hold it close until it's second nature. That will save more important problems, later.


In reply to Re: What is the correct definition of False and Null in Perl? (OT: Formatting of OP) by ww
in thread What is the correct definition of False and Null in Perl? by flexvault

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.