Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Ovid (2709)

  (email not shown publicly)
AOL IM: ovidperl (Add Buddy, Send Message)

Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.

Journal of Ovid (2709)

Sunday March 28, 2004
08:42 PM

Undefined Thought of the Day

[ #18101 ]

So you populate @array with an integer value pulled from the database. Then you have this snippet:

if (grep !$_ => @array) {...}

There's a good chance that this snippet has a bug. If all values are true, then there's no problem. However, what if a value is undefined? To the database, that means "I don't know what this value is." It does not mean "this value is false," so your logic may be suspect. With the latest versions of Perl, we're going to see strange things like this:

if (grep ! ($_ // 1) => @array) {...}

I think my head will melt.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • If you test for truth, you should do that only if you agree with Perl on what is true.

    If you just want to weed out empty strings and zeroes, but want to keep NULLs, do so explicitly:

    grep { not defined xor length and $_ != 0 } @goo
    • Yes, explicitly stating what you want is much cleaner. Still, it would be interesting to create a three-value logic mode in Perl, one where you can know that "undefined" is not false, nor is it greater or less than 13.6 (for example).