I've asked myself that question too. OO-purist or not: why use qw// when you just want to quote one value? How many do print qw(Hello)? Not many, I'd guess. "Unnecessary" qw() seem to be most frequent where lists usually are passed, like array initializations, the vars pragma, import lists, etc, and there it's handy when you want to add something to the list. But as you say, most people do use it with the base pragma too, even though having a list of more than one element there would be the exception, not the rule. I can see a couple of possible explanations, in order of what I think is most likely:
- Cargo-cult. It's used in the pod for base.pm, perlboot, everyone else uses it, so people just copy it.
- Habit. People quite often use qw() with use() statements. I've even seen use Foo qw();.
- Some might have a twisted idea of what a list is. They think that you perhaps must "create" a list somehow, and since the documentation says use Module LIST then people "create" a list with qw().
Update: I don't use
qw() myself when I don't
plan to have more than one element in the list. If I see
use Base qw(Foo) in my own code I suspect I might be planning for MI.
ihb
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.