Mailing List ArchiveSupport open source code!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]Re: perl question
- To: tlug@example.com
- Subject: Re: perl question
- From: shimpei@example.com
- Date: Wed, 25 Jul 2001 18:49:51 +0900
- Delivered-To: tlug@example.com
- List-Help: <mailto:tlug-request@example.comsubject=help>
- List-Post: <mailto:tlug@example.com>
- List-Subscribe: <mailto:tlug-request@example.comsubject=subscribe>
- List-Unsubscribe: <mailto:tlug-request@example.comsubject=unsubscribe>
- Old-Return-Path: <shimpei@example.com>
- Reply-To: tlug@example.com
- Resent-From: tlug@example.com
- Resent-Message-ID: <qSzMBC.A.3_G.gYpX7@example.com>
- Resent-Sender: tlug-request@example.com
> I've got this Perl code > > print qq~ > <$dtd> > <html> > > <head> > blah blah > </html> > ~; > > > Now I understand what this does, it just spits out (in this case) html tags > to stdout. What I don't understand is why. "qq" is an operator that says "the next character, whatever it may be, is to be treated as a double-quote". So everything between ~ immediately after the qq and the next occurance of ~ is treated as a double-quoted string. Read perlop(1) and skip to the "Quote and Quote-like Operators" section for detail. It's useful when you have to embed double-quotes and other meta- characters into your string. For example: print qq/And God said, "Let there be light!"/; is completely equivalent to: print "And God said, \"Let there be light!\""; but the former is more readable once you understand what the qq operator does. In case you're wondering, there is no reason why the writer of that code couldn't have just used double-quotes instead of qq~~, since the text being quoted doesn't have any double-quotes. It's grammatically correct, but needlessly obscure. > The Camel book gives example of here documents using this format > print <<EOF > blah blah > EOF; They both work. The qq operator has the benefit of not screwing up your indentation, while the << syntax frees you from having to look for that one special character that isn't used in the text you're quoting. Remember, the Perl mantra is: There Is More Than One Way To Do It. (I can almost hear the python lovers in the audience snickering over that remark...) > Is this qq thing something new??? Well, it's been there since at least 1996....
- Follow-Ups:
- Re: perl question
- From: "Brett Robson" <brettr@example.com>
- Re: perl question
- From: "Stephen J. Turnbull" <turnbull@example.com>
Home | Main Index | Thread Index
- Prev by Date: RE: sed/vi how to concatenate all non-empty lines?
- Next by Date: Re: sed/vi how to concatenate all non-empty lines?
- Prev by thread: Re: syslog2html or something?
- Next by thread: Re: perl question
- Index(es):
Home Page Mailing List Linux and Japan TLUG Members Links