Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Today in the Chatterbox, maddfisherman had some questions about the heredoc quoting mechanism, and OeufMayo and i started answering him, and brought up some things that tinman didn't know, and that brought up stuff none of us knew, so we ran some test scripts and found some interesting things.

first, some things i did know:

#!/usr/bin/perl -w use strict; my $foo = 'date'; print <<'SINGLE'; $foo SINGLE print <<"DOUBLE"; $foo DOUBLE print <<`BACK`; $foo BACK print <<IMPLIED; $foo IMPLIED
as the experienced heredoc user should know, this prints something like
$foo date Wed Jun 20 15:33:51 PDT 2001 date
Note that with no quotes, double quote interpolation is implied. (note, too, that your date probaby differs from mine.)

but what if you want to use other quoting mechaisms? i wanted to put a big long list into a qw(), and i tried

my @list = <<qw(HERE); Foo Bar Baz HERE
but it can't find string terminator qw.
my @list = qw <<HERE;
can't find string terminator >.
my @list = qw(<< HERE); Foo Bar Baz HERE
did better, but only because i consider the runtime error Can't locate object method "Baz" via package "HERE" at line 23. to be better than not compiling. next step? well, this won't work:
my $bar = <<HERE; Foo Bar Baz HERE my @list = qw($bar);
because the $bar in qw() is not interpolated. this brings up the interesting point of how qw works. further tests seem to indicate that all the quoting functions (q, qq, qr, qw, and qx currently, and i think we get more in perl6) are hard to use with heredocs. in fact, aside from trivial cases, they seem to be hard to use, until you realize that they are operators and not functions. which brings up more questions, like "can we get at the underlying functions?" and "if so, how?" things along those lines.

so, uh, perhaps a heredoc tutorial and a quoters tutorial would be in order.


thanks to maddfisherman, OeufMayo, myocom, and others in the chatterbox for their assistance.

update: fixed some links. and no, CheeseLord i can't think of any specific reason to do it with qw//, but with some of the forthcoming quoting operators, maybe.

update 2: fixed IMPLIED as implied by Particle. bad copying on my part.


In reply to Here, doccy doccy. nice doccy. heredoc, treat. by Vynce

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others contemplating the Monastery: (6)
    As of 2018-06-21 17:24 GMT
    Find Nodes?
      Voting Booth?
      Should cpanminus be part of the standard Perl release?

      Results (118 votes). Check out past polls.