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

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.
  • Maybe you can get him to tap into the community, through this site, perlmonks, various books, etc. Send him links to interesting articles from time to time, until he is reading these sites regularly and learning. He may give more credence when he can see the consensus behind various practices, and he's sure to learn something.

    One of Larry's credos is that it's okay to program in Perl baby talk, and we won't laugh. That may be so, but I'm still pretty ashamed of some of the things I produced more than a

    J. David works really hard, has a passion for writing good software, and knows many of the world's best Perl programmers
  • The first one is actually justified in Perl in the case that you need to return numeric 0 or 1, although you might prefer the ?: operator:

            return ( $dbh ? 1 : 0 );

    Some people, not I, stay away from the ?: like the plague because they think it's unreadable.

    There's a trick I've used in C to turn an integer into 1/0:

            return !!dbh;

    This is too clever, I think, simply:

            return ( dbh != 0 );

    Is probably preferable.


  • What do you do if you see things like this in a script a co-worker wrote:

    Nothing at first. Do they work? Yes. Are they icky? Sure, but they also work. Are they wrong? No, not at all.

    Now, I'm not saying you ignore it, but be logical and methodical about it. "Seek first to understand, then to be understood." Try to understand why the code is written that way. For example:

        if ($dbh) {
            return 1;
        } else {
            return 0;



  • Off the cuff, here's how I would transform this stuff and why.

    if ($dbh) {
      return 1;
    } else {
      return 0;

    That would become:

    return 1 if $dbh;

    Unless there is a demonstrable need to return zero for false, I consider it a bug. What if the results are assigned to an array? The array then has one element, zero, which causes an if (@array) conditional to incorrectly evaluate as true. Further, since boolean tests don't warn about undefined values, why bother to ever return the

  • Oh, just kill him and feed him to the neighborhood cats!