My Favorite Warnings: qw

When I first came to Perl I thought the qw{} construction was pretty neat. Give it a bunch of white-space-delimited text and it gives you back a list separated on the blanks. So

say for qw{ Fee fie foe fum! };

prints 'Fee', 'fie', 'foe', and 'fum!', each on its own line. But if you add punctuation, and warnings are enabled,

say for qw{ Fee, fie, foe, fum! };

gets you 'Possible attempt to separate words with commas ...'.


For a while, I was dealing with this using a weird assortment of quoting techniques. But then I discovered how to tell Perl I meant to do that:

no warnings 'qw';

I do not do this by default, simply because it has caught problems when converting lists from more-usual program literals to qr{} form. For similar reasons I try to restrict the size of the scope of the no warnings.

There is another diagnostic in this warnings category: 'Possible attempt to put comments in qw() list ...'. As you can imagine, this is triggered by something like

say for qw{
    Fee  # First word
    fie  # Second word
    foe  # Third word
    fum! # Fourth word
};

which actually prints sixteen lines rather than four.

Previous entries in this series:

  1. A Belated Introduction
  2. once
  3. redundant and missing
  4. exiting
  5. uninitialized
  6. redefine
  7. Ex-Warnings
  8. deprecated
  9. experimental
  10. shadow
  11. syntax
  12. ambiguous
  13. closure

Leave a comment

About Tom Wyant

user-pic I blog about Perl.