Tanktalus has asked for the wisdom of the Perl Monks concerning the following question:
I find myself doing this a fair bit (though with significantly longer lists - anywhere from 2 to 20 entries, depending):
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 baz );
(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:do_something($_) for qw( foo bar # introduced November, 2005 baz # deprecated - remove by December, 2006 );
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.#!/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; }
Has anyone ever had a similar desire? What solution did you use?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: comments and qw
by brian_d_foy (Abbot) on Feb 12, 2006 at 17:12 UTC | |
|
Re: comments and qw
by rnahi (Curate) on Feb 12, 2006 at 18:33 UTC | |
by ikegami (Patriarch) on Feb 12, 2006 at 19:10 UTC | |
by rnahi (Curate) on Feb 12, 2006 at 20:32 UTC | |
by ikegami (Patriarch) on Feb 13, 2006 at 03:08 UTC | |
|
Re: comments and qw
by Fletch (Bishop) on Feb 12, 2006 at 18:17 UTC | |
|
Re: comments and qw
by bsb (Priest) on Feb 13, 2006 at 09:47 UTC | |
by Roy Johnson (Monsignor) on Feb 13, 2006 at 15:44 UTC | |
|
Re: comments and qw
by stefp (Vicar) on Feb 26, 2006 at 04:01 UTC |