The starting point:
my @array=qw(word1 word2 word3);
Now I want to put each word on a separate line:
my @array=qw(
word1
word2
word3
);
Now I want to add comments:
my @array=qw(
word1 # This is word1
word2 # This is word2
word3 # This is word3
);
The above of course does not work and generates warnings with use warnings.
So, what is the best way to create an array out of a commented list like the above?
I'd recommend avoiding qw
.
my @array = (
'word1', # This is word1
'word2', # This is word2
'word3', # This is word3
);
But you could use Syntax::Feature::QwComments.
use syntax qw( qw_comments );
my @array = qw(
word1 # This is word1
word2 # This is word2
word3 # This is word3
);
Or parse it yourself.
sub myqw { $_[0] =~ s/#[^\n]*//rg =~ /\S+/g }
my @array = myqw(q(
word1 # This is word1
word2 # This is word2
word3 # This is word3
));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With