Sorry for the length and code sloppiness...


Here's some sample code:
use strict; use warnings; my $baz = 0; my $foo = shift || 1; chomp(my @bar = qw( etc etcetera )); die "Nice Try." if $foo < 1; while($baz < $foo){ $baz += 1; print "$bar(bracket)rand @bar(/bracket) ", "ad infinitum\n"; }
Now, my problem with the code as it is(will change later in post) comes when I try to put 0 as a command line option when excecuting the script.

As it is, if you type 0 at the command line, it will still execute, with only one result, as though it had 1 or no option typed at the command line.

I'm guessing it has to do with the nature of the +=, that it will do something even when other commands tell it not to.

I did find a workaround, almost by accident.

Change || to or. However, if you use the default by not typing in an option, it will give this error:

Use of uninitialized value in numeric lt (<) at footest.pl line 9. Nice try. at footest.pl line 9.

Now, I tried a workaround, by changing "shift or 1," to "shift or die." This sort of works, but what happens is that, 1. You have to type a command line option or it will die, and more interestingly, 2. if you type 0 at the command line, it will give the error message for the "shift or die" line, rather than the other die message.

I just checked it by changing the second die line to < 2 and got the error messages like this:

perl footest.pl 1
Nice try. at footest.pl line 9.

perl footest.pl 0
Died at footest.pl line 6.

perl footest.pl -1
Nice try. at footest.pl line 9.

So...I'm thinking that 0 has some sort of special property here, that's making it act that way. Perhaps, as a guess, having to do with it's characteristic as being one of the things that means false?

20050102 Edit by ysth: code and p tags


In reply to fun(?) with += by Anonymous Monk

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.