Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Explain comments in qw// quoted data

by jesuashok (Curate)
on Oct 29, 2005 at 13:17 UTC ( #503859=perlquestion: print w/ replies, xml ) Need Help??
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'

Comment on Explain comments in qw// quoted data
Download Code
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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://503859]
Approved by castaway
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2015-07-06 10:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (72 votes), past polls