http://www.perlmonks.org?node_id=503859

jesuashok has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks,
#!/usr/bin/perl my @list = qw( "a" , # comment "b" , # another comment ); print "val :$_:\n" foreach @list;

when you run the above code all are getting printed. why the perl does not understand the comment inside qw()

I am interested to know what is happening inside. Please explain me in code point if View.

Thanx in advance ...

"Keep pouring your ideas"

2005-10-29 Retitled by davido, as per Monastery guidelines
Original title: 'why the perl behaves like this'

2005-10-30 Retitled by planetscape, as per Monastery guidelines
Original title: 'Explain comments in qr// quoted data'

Replies are listed 'Best First'.
Re: Explain comments in qw// quoted data
by mulander (Monk) on Oct 29, 2005 at 13:29 UTC
    From perldoc perlop:
    qw/STRING/ Evaluates to a list of the words extracted out of STRING, using embedd +ed whitespace as the word delimiters. --removed by me you can see the rest in perldoc perlop-- A common mistake is to try to separate the words with comma or to put +comments into a multi-line qw-string. For this reason, the use warnin +gs pragma and the -w switch (that is, the $^W variable) produces warn +ings if the STRING contains the ``,'' or the ``#'' character.
    As you can see placing placing comments in qw() is a common mistake ;) when in doubt always read the docs, and always use warnings; use strict;.
Re: Explain comments in qw// quoted data
by wfsp (Abbot) on Oct 29, 2005 at 13:31 UTC
    Update:
    Whoops! I didn't see mulander's reply when our ships passed in the night!

    From perlop:

    A common mistake is to try to separate the words with comma or to put comments into a multi-line qw-string. For this reason, the use warnings pragma and the -w switch (that is, the $^W variable) produces warnings if the STRING contains the "," or the "#" character.