I find myself doing this a fair bit (though with significantly longer lists - anywhere from 2 to 20 entries, depending):

do_something($_) for qw( foo bar baz );
It allows me to trivially add something or remove something. Well, removing isn't quite as nice as with regular lists - I can't just comment it out, I have to delete the whole line. However, what I can't do with this is do something like:
do_something($_) for qw( foo bar # introduced November, 2005 baz # deprecated - remove by December, 2006 );
(This does actually tell me it can't do it with a warning message: Possible attempt to put comments in qw() list at ./x.pl line 10.) The closest I can come up with is something like this:
#!/usr/bin/perl use strict; use warnings; do_something($_) for qw( foo bar # introduced November, 2005 baz # deprecated - remove by December, 2006 ); print "-----------------\n"; do_something($_) for words( <<WORDS ); foo bar # introduced November, 2005 baz # deprecated - remove by December, 2006 WORDS sub do_something { print " [$_[0]]\n"; } sub words { my @lines = split /\n/, shift; s/#.*$// for @lines; map { split ' ', $_ } @lines; }
However, I'm pretty sure that it's way slower than any solution that allows the perl parser to do it. And, for some reason, it just doesn't feel elegant. And, for that reason, I haven't actually gone there - I'm not currently inserting comments into my lists.

Has anyone ever had a similar desire? What solution did you use?


In reply to comments and qw by Tanktalus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.