[sf-perl] use {strict,warnings}

Joe Brenner doom at kzsu.stanford.edu
Mon Mar 3 20:04:42 PST 2008


frosty <biztos at mac.com> wrote:

> I think disabling warnings is a slippery slope even in a local
> context.  I suppose if everyone in an organization agreed that
> uninitialized warnings were the enemy it could make sense, but then
> why not take your case to the Perl community at large?

> Of course sometimes you really have to disable warnings of some type
> locally or you'll go nuts, but I try to think of that as a last resort
> and limit it to the smallest possible context.

I think I'm largely in agreement with you here. I do know
that you can shut off a class of warnings lexically, and I
hope it would be obvious that it's best to do this as
minimally as possible.

I think the question for me might be boiled down to this one code
example.  Is it better to code something like this:

  use warnings;
  use strict;

  my @phrases = (
              'The Rediscovery of Man',
              'The Instrumentality',
              'D\'Joan',
  );

  foreach my $phrase (@phrases) {
    my ($alpha, $ralpha, $blvd) = split ' ', $phrase;
    {
      no warnings 'uninitialized';
      print " 1: $alpha\n 2: $ralpha\n 3: $blvd\n\n";
    }
  }

Or should that last loop be handled something like this:

  foreach my $phrase (@phrases) {
    my ($alpha, $ralpha, $blvd) = (' ', ' ', ' ');
    ($alpha, $ralpha, $blvd) = split ' ', $phrase;
    $alpha  ||='';
    $ralpha ||='';
    $blvd   ||='';
    print " 1: $alpha\n 2: $ralpha\n 3: $blvd\n\n";
  }

In this particular case it's something of a wash in terms of
complexity or dangerousness, but you don't have to think as
hard about the second way, so I think that one wins.

I would guess that just leaving warnings on all the time wins
often enough that you're better off doing it that way by
default, and living with the occasional minor pain.



More information about the SanFrancisco-pm mailing list